paralysis 2.0.0 → 2.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/dist/index.cjs +13 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/paralysis.js +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var TinyQueue = require('tinyqueue');
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
if (typeof fn !== "function") {
|
|
7
|
-
throw new TypeError(`${fn} is not a function`);
|
|
8
|
-
}
|
|
9
|
-
if (!(typeof concurrency === "number" && concurrency >= 1)) {
|
|
10
|
-
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
11
|
-
}
|
|
5
|
+
function createRun(concurrency) {
|
|
12
6
|
const queue = new TinyQueue();
|
|
13
7
|
let slots = Math.floor(concurrency);
|
|
14
8
|
function release() {
|
|
@@ -20,12 +14,12 @@ function paralysis(list, fn, concurrency = Infinity) {
|
|
|
20
14
|
slots++;
|
|
21
15
|
}
|
|
22
16
|
}
|
|
23
|
-
function runRecipe([
|
|
17
|
+
function runRecipe([fn, args]) {
|
|
24
18
|
return new Promise((resolve) => {
|
|
25
|
-
resolve(
|
|
19
|
+
resolve(fn(...args));
|
|
26
20
|
}).finally(release);
|
|
27
21
|
}
|
|
28
|
-
function run(recipe) {
|
|
22
|
+
return function run(recipe) {
|
|
29
23
|
if (slots > 0) {
|
|
30
24
|
slots--;
|
|
31
25
|
return runRecipe(recipe);
|
|
@@ -33,7 +27,16 @@ function paralysis(list, fn, concurrency = Infinity) {
|
|
|
33
27
|
return new Promise((resolve) => {
|
|
34
28
|
queue.push([resolve, recipe]);
|
|
35
29
|
}).then(runRecipe);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function paralysis(list, fn, concurrency = Infinity) {
|
|
33
|
+
if (typeof fn !== "function") {
|
|
34
|
+
throw new TypeError(`${fn} is not a function`);
|
|
35
|
+
}
|
|
36
|
+
if (!(typeof concurrency === "number" && concurrency >= 1)) {
|
|
37
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
36
38
|
}
|
|
39
|
+
const run = createRun(concurrency);
|
|
37
40
|
return Promise.all(Array.from(list, (...args) => run([fn, args])));
|
|
38
41
|
}
|
|
39
42
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\n\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\n\nfunction createRun(concurrency) {\n const queue = new TinyQueue();\n let slots = Math.floor(concurrency);\n\n function release() {\n // Check if we have more functions waiting in the queue. If we\n // do, run the next delayed function. Otherwise, free a slot.\n const next = queue.pop();\n if (next) {\n const [resolve, delayed] = next;\n resolve(delayed);\n } else {\n slots++;\n }\n }\n\n function runRecipe([fn, args]) {\n // Note that if `fn` throws a synchronous error\n // inside it will reject the promise. This wouldn't\n // happen if we used `Promise.resolve()` directly.\n return new Promise((resolve) => {\n resolve(fn(...args));\n }).finally(release);\n }\n\n return function run(recipe) {\n // If we have an available slot, take the slot and return\n // a promise that executes the function immediately.\n if (slots > 0) {\n slots--;\n return runRecipe(recipe);\n }\n\n // If the limit of slots is reached, enqueue the function\n // and return a promise that will be resolved only after\n // the next slot is released and the function is executed.\n return new Promise((resolve) => {\n queue.push([resolve, recipe]);\n }).then(runRecipe);\n };\n}\n\nexport function paralysis(list, fn, concurrency = Infinity) {\n if (typeof fn !== \"function\") {\n throw new TypeError(`${fn} is not a function`);\n }\n\n if (!(typeof concurrency === \"number\" && concurrency >= 1)) {\n throw new TypeError(\"Expected `concurrency` to be a number from 1 and up\");\n }\n\n const run = createRun(concurrency);\n return Promise.all(Array.from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,CAAA,EAAG,EAAE,CAAA,kBAAA,CAAoB,CAAA;AAAA,EAC/C;AAEA,EAAA,IAAI,EAAE,OAAO,WAAA,KAAgB,QAAA,IAAY,eAAe,CAAA,CAAA,EAAI;AAC1D,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AAEA,EAAA,MAAM,GAAA,GAAM,UAAU,WAAW,CAAA;AACjC,EAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAA,CAAM,IAAA,CAAK,IAAA,EAAM,CAAA,GAAI,IAAA,KAAS,GAAA,CAAI,CAAC,EAAA,EAAI,IAAI,CAAC,CAAC,CAAC,CAAA;AACnE;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import TinyQueue from 'tinyqueue';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
if (typeof fn !== "function") {
|
|
5
|
-
throw new TypeError(`${fn} is not a function`);
|
|
6
|
-
}
|
|
7
|
-
if (!(typeof concurrency === "number" && concurrency >= 1)) {
|
|
8
|
-
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
9
|
-
}
|
|
3
|
+
function createRun(concurrency) {
|
|
10
4
|
const queue = new TinyQueue();
|
|
11
5
|
let slots = Math.floor(concurrency);
|
|
12
6
|
function release() {
|
|
@@ -18,12 +12,12 @@ function paralysis(list, fn, concurrency = Infinity) {
|
|
|
18
12
|
slots++;
|
|
19
13
|
}
|
|
20
14
|
}
|
|
21
|
-
function runRecipe([
|
|
15
|
+
function runRecipe([fn, args]) {
|
|
22
16
|
return new Promise((resolve) => {
|
|
23
|
-
resolve(
|
|
17
|
+
resolve(fn(...args));
|
|
24
18
|
}).finally(release);
|
|
25
19
|
}
|
|
26
|
-
function run(recipe) {
|
|
20
|
+
return function run(recipe) {
|
|
27
21
|
if (slots > 0) {
|
|
28
22
|
slots--;
|
|
29
23
|
return runRecipe(recipe);
|
|
@@ -31,7 +25,16 @@ function paralysis(list, fn, concurrency = Infinity) {
|
|
|
31
25
|
return new Promise((resolve) => {
|
|
32
26
|
queue.push([resolve, recipe]);
|
|
33
27
|
}).then(runRecipe);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function paralysis(list, fn, concurrency = Infinity) {
|
|
31
|
+
if (typeof fn !== "function") {
|
|
32
|
+
throw new TypeError(`${fn} is not a function`);
|
|
33
|
+
}
|
|
34
|
+
if (!(typeof concurrency === "number" && concurrency >= 1)) {
|
|
35
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
34
36
|
}
|
|
37
|
+
const run = createRun(concurrency);
|
|
35
38
|
return Promise.all(Array.from(list, (...args) => run([fn, args])));
|
|
36
39
|
}
|
|
37
40
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\n\
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\n\nfunction createRun(concurrency) {\n const queue = new TinyQueue();\n let slots = Math.floor(concurrency);\n\n function release() {\n // Check if we have more functions waiting in the queue. If we\n // do, run the next delayed function. Otherwise, free a slot.\n const next = queue.pop();\n if (next) {\n const [resolve, delayed] = next;\n resolve(delayed);\n } else {\n slots++;\n }\n }\n\n function runRecipe([fn, args]) {\n // Note that if `fn` throws a synchronous error\n // inside it will reject the promise. This wouldn't\n // happen if we used `Promise.resolve()` directly.\n return new Promise((resolve) => {\n resolve(fn(...args));\n }).finally(release);\n }\n\n return function run(recipe) {\n // If we have an available slot, take the slot and return\n // a promise that executes the function immediately.\n if (slots > 0) {\n slots--;\n return runRecipe(recipe);\n }\n\n // If the limit of slots is reached, enqueue the function\n // and return a promise that will be resolved only after\n // the next slot is released and the function is executed.\n return new Promise((resolve) => {\n queue.push([resolve, recipe]);\n }).then(runRecipe);\n };\n}\n\nexport function paralysis(list, fn, concurrency = Infinity) {\n if (typeof fn !== \"function\") {\n throw new TypeError(`${fn} is not a function`);\n }\n\n if (!(typeof concurrency === \"number\" && concurrency >= 1)) {\n throw new TypeError(\"Expected `concurrency` to be a number from 1 and up\");\n }\n\n const run = createRun(concurrency);\n return Promise.all(Array.from(list, (...args) => run([fn, args])));\n}\n"],"names":[],"mappings":";;AAEA,SAAS,UAAU,WAAA,EAAa;AAC9B,EAAA,MAAM,KAAA,GAAQ,IAAI,SAAA,EAAU;AAC5B,EAAA,IAAI,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,WAAW,CAAA;AAElC,EAAA,SAAS,OAAA,GAAU;AAGjB,IAAA,MAAM,IAAA,GAAO,MAAM,GAAA,EAAI;AACvB,IAAA,IAAI,IAAA,EAAM;AACR,MAAA,MAAM,CAAC,OAAA,EAAS,OAAO,CAAA,GAAI,IAAA;AAC3B,MAAA,OAAA,CAAQ,OAAO,CAAA;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,KAAA,EAAA;AAAA,IACF;AAAA,EACF;AAEA,EAAA,SAAS,SAAA,CAAU,CAAC,EAAA,EAAI,IAAI,CAAA,EAAG;AAI7B,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY;AAC9B,MAAA,OAAA,CAAQ,EAAA,CAAG,GAAG,IAAI,CAAC,CAAA;AAAA,IACrB,CAAC,CAAA,CAAE,OAAA,CAAQ,OAAO,CAAA;AAAA,EACpB;AAEA,EAAA,OAAO,SAAS,IAAI,MAAA,EAAQ;AAG1B,IAAA,IAAI,QAAQ,CAAA,EAAG;AACb,MAAA,KAAA,EAAA;AACA,MAAA,OAAO,UAAU,MAAM,CAAA;AAAA,IACzB;AAKA,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY;AAC9B,MAAA,KAAA,CAAM,IAAA,CAAK,CAAC,OAAA,EAAS,MAAM,CAAC,CAAA;AAAA,IAC9B,CAAC,CAAA,CAAE,IAAA,CAAK,SAAS,CAAA;AAAA,EACnB,CAAA;AACF;AAEO,SAAS,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI,WAAA,GAAc,QAAA,EAAU;AAC1D,EAAA,IAAI,OAAO,OAAO,UAAA,EAAY;AAC5B,IAAA,MAAM,IAAI,SAAA,CAAU,CAAA,EAAG,EAAE,CAAA,kBAAA,CAAoB,CAAA;AAAA,EAC/C;AAEA,EAAA,IAAI,EAAE,OAAO,WAAA,KAAgB,QAAA,IAAY,eAAe,CAAA,CAAA,EAAI;AAC1D,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AAEA,EAAA,MAAM,GAAA,GAAM,UAAU,WAAW,CAAA;AACjC,EAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAA,CAAM,IAAA,CAAK,IAAA,EAAM,CAAA,GAAI,IAAA,KAAS,GAAA,CAAI,CAAC,EAAA,EAAI,IAAI,CAAC,CAAC,CAAC,CAAA;AACnE;;;;"}
|
package/package.json
CHANGED
package/src/paralysis.js
CHANGED
|
@@ -17,7 +17,7 @@ function createRun(concurrency) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function runRecipe([fn, args]) {
|
|
20
|
-
// Note that if `fn` throws
|
|
20
|
+
// Note that if `fn` throws a synchronous error
|
|
21
21
|
// inside it will reject the promise. This wouldn't
|
|
22
22
|
// happen if we used `Promise.resolve()` directly.
|
|
23
23
|
return new Promise((resolve) => {
|