simple-p-limit 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +10 -128
- package/lib/index.js +8 -13
- package/package.json +5 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
|
3
|
+
Copyright (c) 2025-26 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,52 +1,13 @@
|
|
|
1
1
|
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
3
|
# simple-p-limit
|
|
21
4
|
|
|
22
5
|
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://www.npmjs.com/package/simple-p-limit) [](https://www.npmjs.com/package/simple-p-limit) [](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
|
|
23
6
|
|
|
24
7
|
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
|
|
25
8
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
9
|
> A simple implementation of concurent promises with a limit.
|
|
33
10
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
11
|
## :cloud: Installation
|
|
51
12
|
|
|
52
13
|
```sh
|
|
@@ -57,22 +18,8 @@ npm install --save simple-p-limit
|
|
|
57
18
|
yarn add simple-p-limit
|
|
58
19
|
```
|
|
59
20
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
21
|
## :clipboard: Example
|
|
73
22
|
|
|
74
|
-
|
|
75
|
-
|
|
76
23
|
```js
|
|
77
24
|
const simplePLimit = require("simple-p-limit");
|
|
78
25
|
|
|
@@ -96,114 +43,49 @@ const simplePLimit = require("simple-p-limit");
|
|
|
96
43
|
})();
|
|
97
44
|
```
|
|
98
45
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
46
|
## :memo: Documentation
|
|
110
47
|
|
|
111
|
-
|
|
112
48
|
### `simplePLimit(concurrency)`
|
|
113
49
|
A simple implementation of concurent promises with a limit.
|
|
114
50
|
|
|
115
51
|
#### Params
|
|
116
|
-
|
|
117
52
|
- **Number** `concurrency`: How many functions returning a promise should run in parallel.
|
|
118
53
|
|
|
119
54
|
#### Return
|
|
120
55
|
- **Function** The `limit` function.
|
|
121
56
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
57
|
## :question: Get Help
|
|
131
58
|
|
|
132
|
-
There are few ways to get help:
|
|
133
|
-
|
|
59
|
+
There are a few ways to get help:
|
|
134
60
|
|
|
135
|
-
|
|
136
|
-
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
|
|
61
|
+
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long as you add a link to your Stack Overflow question.
|
|
137
62
|
2. For bug reports and feature requests, open issues. :bug:
|
|
138
63
|
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
139
64
|
|
|
65
|
+
## :yum: How to Contribute
|
|
140
66
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
## :yum: How to contribute
|
|
154
67
|
Have an idea? Found a bug? See [how to contribute][contributing].
|
|
155
68
|
|
|
69
|
+
## :sparkling_heart: Support My Projects
|
|
156
70
|
|
|
157
|
-
|
|
158
|
-
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
|
|
159
|
-
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
|
|
160
|
-
|
|
161
|
-
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
|
|
71
|
+
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute it (even resell it).
|
|
162
72
|
|
|
73
|
+
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are a few ways you can do it:
|
|
163
74
|
|
|
164
75
|
- Starring and sharing the projects you like :rocket:
|
|
165
|
-
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you
|
|
76
|
+
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you for years if you buy me one. :grin: :book:
|
|
166
77
|
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
|
|
167
78
|
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
|
|
168
|
-
- **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
|
169
|
-
|
|
170
|
-

|
|
79
|
+
- **Bitcoin**—You can send me bitcoins at this address (or by scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
|
171
80
|
|
|
81
|
+

|
|
172
82
|
|
|
173
83
|
Thanks! :heart:
|
|
174
84
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
85
|
## :scroll: License
|
|
199
86
|
|
|
200
87
|
[MIT][license] © [Ionică Bizău][website]
|
|
201
88
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
89
|
[license]: /LICENSE
|
|
208
90
|
[website]: https://ionicabizau.net
|
|
209
91
|
[contributing]: /CONTRIBUTING.md
|
|
@@ -213,5 +95,5 @@ Thanks! :heart:
|
|
|
213
95
|
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
|
|
214
96
|
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
|
|
215
97
|
[patreon]: https://www.patreon.com/ionicabizau
|
|
216
|
-
[amazon]:
|
|
98
|
+
[amazon]: https://amzn.eu/hRo9sIZ
|
|
217
99
|
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
|
package/lib/index.js
CHANGED
|
@@ -9,22 +9,16 @@
|
|
|
9
9
|
* @param {Number} concurrency How many functions returning a promise should run in parallel.
|
|
10
10
|
* @return {Function} The `limit` function.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
module.exports = function simplePLimit(concurrency) {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const queue = [];
|
|
14
|
+
let activeCount = 0;
|
|
16
15
|
|
|
17
16
|
async function next() {
|
|
18
17
|
if (queue.length === 0 || activeCount >= concurrency) return;
|
|
19
18
|
activeCount++;
|
|
20
|
-
|
|
21
|
-
var _queue$shift = queue.shift(),
|
|
22
|
-
fn = _queue$shift.fn,
|
|
23
|
-
resolve = _queue$shift.resolve,
|
|
24
|
-
reject = _queue$shift.reject;
|
|
25
|
-
|
|
19
|
+
const { fn, resolve, reject } = queue.shift();
|
|
26
20
|
try {
|
|
27
|
-
resolve(
|
|
21
|
+
resolve(await fn());
|
|
28
22
|
} catch (error) {
|
|
29
23
|
reject(error);
|
|
30
24
|
} finally {
|
|
@@ -34,9 +28,10 @@ module.exports = function simplePLimit(concurrency) {
|
|
|
34
28
|
}
|
|
35
29
|
|
|
36
30
|
return function (fn) {
|
|
37
|
-
return new Promise(
|
|
38
|
-
queue.push({ fn
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
queue.push({ fn, resolve, reject });
|
|
39
33
|
next();
|
|
40
34
|
});
|
|
41
35
|
};
|
|
42
|
-
}
|
|
36
|
+
}
|
|
37
|
+
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"promises"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.1",
|
|
13
13
|
"main": "lib/index.js",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"cli.js",
|
|
29
29
|
"index.js",
|
|
30
30
|
"index.d.ts",
|
|
31
|
-
"
|
|
31
|
+
"bloggify.js",
|
|
32
|
+
"bloggify.json",
|
|
33
|
+
"bloggify/"
|
|
32
34
|
],
|
|
33
35
|
"repository": {
|
|
34
36
|
"type": "git",
|
|
@@ -37,4 +39,4 @@
|
|
|
37
39
|
"bugs": {
|
|
38
40
|
"url": "https://github.com/IonicaBizau/simple-p-limit/issues"
|
|
39
41
|
}
|
|
40
|
-
}
|
|
42
|
+
}
|