Welcome to mirror list, hosted at ThFree Co, Russian Federation.

README.md « call-limit « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 590ca419ee6cf9b7a21b9b97d2f40c79c39cb11c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
call-limit
----------

Limit the number of simultaneous executions of a async function.

```javascript
var fs = require('fs')
var limit = require('call-limit')
var limitedStat = limit(fs.stat, 5)
```

Or with promise returning functions:

```javascript
var fs = Bluebird.promisifyAll(require('fs'))
var limit = require('call-limit')
var limitedStat = limit.promise(fs.statAsync, 5)
```

### USAGE:

Given that:

```javascript
var limit = require('call-limit')
```

### limit(func, maxRunning) → limitedFunc

The returned function will execute up to maxRunning calls of `func` at once. 
Beyond that they get queued and called when the previous call completes.

`func` must accept a callback as the final argument and must call it when
it completes, or `call-limit` won't know to dequeue the next thing to run.

By contrast, callers to `limitedFunc` do NOT have to pass in a callback, but
if they do they'll be called when `func` calls its callback.

### limit.promise(func, maxRunning) → limitedFunc

The returned function will execute up to maxRunning calls of `func` at once.
Beyond that they get queued and called when the previous call completes.

`func` must return a promise.

`limitedFunc` will return a promise that resolves with the promise returned
from the call to `func`.

### limit.method(class, methodName, maxRunning)

This is sugar for:

```javascript
class.prototype.methodName = limit(class.prototype.methodName, maxRunning)
```

### limit.method(object, methodName, maxRunning)

This is sugar for:

```javascript
object.methodName = limit(object.methodName, maxRunning)
```

For example `limit.promise.method(fs, 'stat', 5)` is the same as
`fs.stat = limit.promise(fs.stat, 5)`.

### limit.promise.method(class, methodName, maxRunning)

This is sugar for:

```javascript
class.prototype.methodName = limit.promise(class.prototype.methodName, maxRunning)
```

### limit.promise.method(object, methodName, maxRunning)

This is sugar for:

```javascript
object.methodName = limit.promise(object.methodName, maxRunning)
```

For example `limit.promise.method(fs, 'statAsync', 5)` is the same as
`fs.statAsync = limit.promise(fs.statAsync, 5)`.