1 | call-limit
|
2 | ----------
|
3 |
|
4 | Limit the number of simultaneous executions of a async function.
|
5 |
|
6 | ```javascript
|
7 | var fs = require('fs')
|
8 | var limit = require('call-limit')
|
9 | var limitedStat = limit(fs.stat, 5)
|
10 | ```
|
11 |
|
12 |
|
13 | ### USAGE:
|
14 |
|
15 | Given that:
|
16 |
|
17 | ```javascript
|
18 | var limit = require('call-limit')
|
19 | ```
|
20 |
|
21 | ### limit(func, maxRunning) → limitedFunc
|
22 |
|
23 | The returned function will execute up to maxRunning calls of `func` at once.
|
24 | Beyond that they get queued and called when the previous call completes.
|
25 |
|
26 | `func` must accept a callback as the final argument and must call it when
|
27 | it completes, or `call-limit` won't know to dequeue the next thing to run.
|
28 |
|
29 | By contrast, callers to `limitedFunc` do NOT have to pass in a callback, but
|
30 | if they do they'll be called when `func` calls its callback.
|
31 |
|
32 | ### limit.method(class, methodName, maxRunning)
|
33 |
|
34 | This is sugar for:
|
35 |
|
36 | ```javascript
|
37 | class.prototype.methodName = limit(class.prototype.methodName, maxRunning)
|
38 | ```
|
39 |
|
40 | ### limit.method(object, methodName, maxRunning)
|
41 |
|
42 | This is sugar for:
|
43 |
|
44 | ```javascript
|
45 | object.methodName = limit(object.methodName, maxRunning)
|
46 | ```
|