1call-limit
2----------
3
4Limit the number of simultaneous executions of a async function.
5
6```javascript
7const fs = require('fs')
8const limit = require('call-limit')
9const limitedStat = limit(fs.stat, 5)
10```
11
12Or with promise returning functions:
13
14```javascript
15const fs = Bluebird.promisifyAll(require('fs'))
16const limit = require('call-limit')
17const limitedStat = limit.promise(fs.statAsync, 5)
18```
19
20### USAGE:
21
22Given that:
23
24```javascript
25const limit = require('call-limit')
26```
27
28### limit(func, maxRunning) → limitedFunc
29
30The returned function will execute up to maxRunning calls of `func` at once.
31Beyond that they get queued and called when the previous call completes.
32
33`func` must accept a callback as the final argument and must call it when
34it completes, or `call-limit` won't know to dequeue the next thing to run.
35
36By contrast, callers to `limitedFunc` do NOT have to pass in a callback, but
37if they do they'll be called when `func` calls its callback.
38
39### limit.promise(func, maxRunning) → limitedFunc
40
41The returned function will execute up to maxRunning calls of `func` at once.
42Beyond that they get queued and called when the previous call completes.
43
44`func` must return a promise.
45
46`limitedFunc` will return a promise that resolves with the promise returned
47from the call to `func`.
48
49### limit.method(class, methodName, maxRunning)
50
51This is sugar for:
52
53```javascript
54class.prototype.methodName = limit(class.prototype.methodName, maxRunning)
55```
56
57### limit.method(object, methodName, maxRunning)
58
59This is sugar for:
60
61```javascript
62object.methodName = limit(object.methodName, maxRunning)
63```
64
65For example `limit.promise.method(fs, 'stat', 5)` is the same as
66`fs.stat = limit.promise(fs.stat, 5)`.
67
68### limit.promise.method(class, methodName, maxRunning)
69
70This is sugar for:
71
72```javascript
73class.prototype.methodName = limit.promise(class.prototype.methodName, maxRunning)
74```
75
76### limit.promise.method(object, methodName, maxRunning)
77
78This is sugar for:
79
80```javascript
81object.methodName = limit.promise(object.methodName, maxRunning)
82```
83
84For example `limit.promise.method(fs, 'statAsync', 5)` is the same as
85`fs.statAsync = limit.promise(fs.statAsync, 5)`.
86