paralysis 2.0.2 → 2.1.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 +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/paralysis.js +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var TinyQueue = require('tinyqueue');
|
|
4
|
+
var toArray = require('to-array');
|
|
4
5
|
|
|
5
6
|
function createRun(concurrency) {
|
|
6
7
|
const queue = new TinyQueue();
|
|
@@ -37,7 +38,7 @@ function paralysis(list, fn, concurrency = Infinity) {
|
|
|
37
38
|
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
38
39
|
}
|
|
39
40
|
const run = createRun(concurrency);
|
|
40
|
-
return Promise.all(
|
|
41
|
+
return Promise.all(toArray(list).map((...args) => run([fn, args])));
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
module.exports = paralysis;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 inside\n // `new Promise()` it will reject the promise. This\n // wouldn't 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(
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\nimport toArray from \"to-array\";\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 inside\n // `new Promise()` it will reject the promise. This\n // wouldn't 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(toArray(list).map((...args) => run([fn, args])));\n}\n"],"names":[],"mappings":";;;;;AAGA,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,OAAA,CAAQ,IAAI,EAAE,GAAA,CAAI,CAAA,GAAI,IAAA,KAAS,GAAA,CAAI,CAAC,EAAA,EAAI,IAAI,CAAC,CAAC,CAAC,CAAA;AACpE;;;;"}
|
package/dist/index.d.cts
CHANGED
|
@@ -30,7 +30,7 @@ type Promisable<T> = T | PromiseLike<T>;
|
|
|
30
30
|
*/
|
|
31
31
|
declare function paralysis<T, U>(
|
|
32
32
|
list: ArrayLike<T>,
|
|
33
|
-
fn: (
|
|
33
|
+
fn: (value: T, index: number, array: Array<T>) => Promisable<U>,
|
|
34
34
|
concurrency?: number,
|
|
35
35
|
): Promise<Array<U>>;
|
|
36
36
|
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sources":["../src/index.d.ts"],"mappings":"AAAA,KAAK,UAAU,UAAU,WAAW;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;iBACwB,SAAS;AACjC,QAAQ,SAAS;AACjB,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sources":["../src/index.d.ts"],"mappings":"AAAA,KAAK,UAAU,UAAU,WAAW;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;iBACwB,SAAS;AACjC,QAAQ,SAAS;AACjB,uCAAuC,KAAK,QAAQ,UAAU;AAC9D;AACA,GAAG,OAAO,CAAC,KAAK;;;;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -30,7 +30,7 @@ type Promisable<T> = T | PromiseLike<T>;
|
|
|
30
30
|
*/
|
|
31
31
|
declare function paralysis<T, U>(
|
|
32
32
|
list: ArrayLike<T>,
|
|
33
|
-
fn: (
|
|
33
|
+
fn: (value: T, index: number, array: Array<T>) => Promisable<U>,
|
|
34
34
|
concurrency?: number,
|
|
35
35
|
): Promise<Array<U>>;
|
|
36
36
|
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sources":["../src/index.d.ts"],"mappings":"AAAA,KAAK,UAAU,UAAU,WAAW;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;iBACwB,SAAS;AACjC,QAAQ,SAAS;AACjB,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sources":["../src/index.d.ts"],"mappings":"AAAA,KAAK,UAAU,UAAU,WAAW;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;iBACwB,SAAS;AACjC,QAAQ,SAAS;AACjB,uCAAuC,KAAK,QAAQ,UAAU;AAC9D;AACA,GAAG,OAAO,CAAC,KAAK;;;;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import TinyQueue from 'tinyqueue';
|
|
2
|
+
import toArray from 'to-array';
|
|
2
3
|
|
|
3
4
|
function createRun(concurrency) {
|
|
4
5
|
const queue = new TinyQueue();
|
|
@@ -35,7 +36,7 @@ function paralysis(list, fn, concurrency = Infinity) {
|
|
|
35
36
|
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
36
37
|
}
|
|
37
38
|
const run = createRun(concurrency);
|
|
38
|
-
return Promise.all(
|
|
39
|
+
return Promise.all(toArray(list).map((...args) => run([fn, args])));
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export { paralysis as default };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 inside\n // `new Promise()` it will reject the promise. This\n // wouldn't 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(
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\nimport toArray from \"to-array\";\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 inside\n // `new Promise()` it will reject the promise. This\n // wouldn't 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(toArray(list).map((...args) => run([fn, args])));\n}\n"],"names":[],"mappings":";;;AAGA,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,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;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paralysis",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Map over promises concurrently",
|
|
5
5
|
"repository": "th3rius/paralysis",
|
|
6
6
|
"keywords": [
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"tinyqueue": "^2.0.3"
|
|
37
|
+
"tinyqueue": "^2.0.3",
|
|
38
|
+
"to-array": "^0.1.4"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@faker-js/faker": "^10.2.0",
|
package/src/paralysis.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import TinyQueue from "tinyqueue";
|
|
2
|
+
import toArray from "to-array";
|
|
2
3
|
|
|
3
4
|
function createRun(concurrency) {
|
|
4
5
|
const queue = new TinyQueue();
|
|
@@ -52,5 +53,5 @@ export function paralysis(list, fn, concurrency = Infinity) {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
const run = createRun(concurrency);
|
|
55
|
-
return Promise.all(
|
|
56
|
+
return Promise.all(toArray(list ?? []).map((...args) => run([fn, args])));
|
|
56
57
|
}
|