UNPKG

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