paralysis 2.1.1 → 2.1.2

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 CHANGED
@@ -38,7 +38,7 @@ function paralysis(list, fn, concurrency = Infinity) {
38
38
  throw new TypeError("Expected `concurrency` to be a number from 1 and up");
39
39
  }
40
40
  const run = createRun(concurrency);
41
- return Promise.all(toArray(list).map((...args) => run([fn, args])));
41
+ return Promise.all(toArray(list ?? []).map((...args) => run([fn, args])));
42
42
  }
43
43
 
44
44
  module.exports = paralysis;
@@ -1 +1 @@
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) =>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AAG,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;;;;"}
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 }\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AY;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,QAAQ,GAAA,CAAI,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAA,GAAI,IAAA,KAAS,IAAI,CAAC,EAAA,EAAI,IAAI,CAAC,CAAC,CAAC,CAAA;AAC1E;;;;"}
package/dist/index.mjs CHANGED
@@ -36,7 +36,7 @@ function paralysis(list, fn, concurrency = Infinity) {
36
36
  throw new TypeError("Expected `concurrency` to be a number from 1 and up");
37
37
  }
38
38
  const run = createRun(concurrency);
39
- return Promise.all(toArray(list).map((...args) => run([fn, args])));
39
+ return Promise.all(toArray(list ?? []).map((...args) => run([fn, args])));
40
40
  }
41
41
 
42
42
  export { paralysis as default };
@@ -1 +1 @@
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,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;;;;"}
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,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,QAAQ,GAAA,CAAI,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAA,GAAI,IAAA,KAAS,IAAI,CAAC,EAAA,EAAI,IAAI,CAAC,CAAC,CAAC,CAAA;AAC1E;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paralysis",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Map over promises concurrently",
5
5
  "repository": "th3rius/paralysis",
6
6
  "keywords": [