@@ -24,53 +24,53 @@ Installation of the [npm package](https://npmjs.org/package/limit-concurrency-de
24
24
Simply apply the decorator to a method:
25
25
26
26
``` js
27
- import limit from ' limit-concurrency-decorator'
27
+ import limit from " limit-concurrency-decorator" ;
28
28
29
29
class HttpClient {
30
30
@limit (2 )
31
- get () {
31
+ get () {
32
32
// ...
33
33
}
34
34
}
35
35
36
- const client = new HttpClient ()
36
+ const client = new HttpClient ();
37
37
38
38
// these calls will run in parallel
39
- client .get (' http://example.net/' )
40
- client .get (' http://example2.net/' )
39
+ client .get (" http://example.net/" );
40
+ client .get (" http://example2.net/" );
41
41
42
42
// this call will wait for the 2 previous to finish
43
- client .get (' http://example3.net/' )
43
+ client .get (" http://example3.net/" );
44
44
```
45
45
46
46
Or a simple function as a wrapper:
47
47
48
48
``` js
49
- import httpRequest from ' http-request-plus'
49
+ import httpRequest from " http-request-plus" ;
50
50
51
- const httpRequestLimited = limit (2 )(httpRequest)
51
+ const httpRequestLimited = limit (2 )(httpRequest);
52
52
53
53
// these calls will run in parallel
54
- httpRequestLimited (' http://example.net/' )
55
- httpRequestLimited (' http://example2.net/' )
54
+ httpRequestLimited (" http://example.net/" );
55
+ httpRequestLimited (" http://example2.net/" );
56
56
57
57
// this call will wait for the 2 previous to finish
58
- httpRequestLimited (' http://example3.net/' )
58
+ httpRequestLimited (" http://example3.net/" );
59
59
```
60
60
61
61
The limit can be shared:
62
62
63
63
``` js
64
- const myLimit = limit (2 )
64
+ const myLimit = limit (2 );
65
65
66
66
class HttpClient {
67
67
@myLimit
68
- post () {
68
+ post () {
69
69
// ...
70
70
}
71
71
72
72
@myLimit
73
- put () {
73
+ put () {
74
74
// ...
75
75
}
76
76
}
@@ -79,32 +79,32 @@ class HttpClient {
79
79
With ` FAIL_ON_QUEUE ` you can fail early instead of waiting:
80
80
81
81
``` js
82
- import { FAIL_ON_QUEUE } from ' limit-concurrency-decorator'
82
+ import { FAIL_ON_QUEUE } from " limit-concurrency-decorator" ;
83
83
84
84
try {
85
- await httpRequestLimited (FAIL_ON_QUEUE , ' http://example2.net' )
85
+ await httpRequestLimited (FAIL_ON_QUEUE , " http://example2.net" );
86
86
} catch (error) {
87
- error .message // 'no available place in queue'
87
+ error .message ; // 'no available place in queue'
88
88
}
89
89
```
90
90
91
91
Custom termination:
92
92
93
93
``` js
94
94
const httpRequestLimited = limit (2 , async promise => {
95
- const stream = await promise
95
+ const stream = await promise;
96
96
await new Promise (resolve => {
97
- stream .on (' end' , resolve)
98
- stream .on (' error' , reject)
99
- })
100
- })(httpRequest)
97
+ stream .on (" end" , resolve);
98
+ stream .on (" error" , reject);
99
+ });
100
+ })(httpRequest);
101
101
102
102
// these calls will run in parallel
103
- httpRequestLimited (' http://example.net/' )
104
- httpRequestLimited (' http://example2.net/' )
103
+ httpRequestLimited (" http://example.net/" );
104
+ httpRequestLimited (" http://example2.net/" );
105
105
106
106
// this call will wait for the 2 previous responses to have been read entirely
107
- httpRequestLimited (' http://example3.net/' )
107
+ httpRequestLimited (" http://example3.net/" );
108
108
```
109
109
110
110
## Development
@@ -128,7 +128,7 @@ httpRequestLimited('http://example3.net/')
128
128
129
129
## Contributions
130
130
131
- Contributions are * very * welcomed, either on the documentation or on
131
+ Contributions are _ very _ welcomed, either on the documentation or on
132
132
the code.
133
133
134
134
You may:
0 commit comments