paralysis 1.0.2 → 1.0.4

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
@@ -2,7 +2,10 @@
2
2
 
3
3
  var TinyQueue = require('tinyqueue');
4
4
 
5
- function createRun(concurrency) {
5
+ function paralysis(list, fn, concurrency = Infinity) {
6
+ if (!(typeof concurrency === "number" && concurrency >= 1)) {
7
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
8
+ }
6
9
  const queue = new TinyQueue();
7
10
  let slots = Math.floor(concurrency);
8
11
  function release() {
@@ -14,12 +17,12 @@ function createRun(concurrency) {
14
17
  slots++;
15
18
  }
16
19
  }
17
- function runRecipe([fn, args]) {
20
+ function runRecipe([fn2, args]) {
18
21
  return new Promise((resolve) => {
19
- resolve(fn(...args));
22
+ resolve(fn2(...args));
20
23
  }).finally(release);
21
24
  }
22
- return function run(recipe) {
25
+ function run(recipe) {
23
26
  if (slots > 0) {
24
27
  slots--;
25
28
  return runRecipe(recipe);
@@ -27,13 +30,7 @@ function createRun(concurrency) {
27
30
  return new Promise((resolve) => {
28
31
  queue.push([resolve, recipe]);
29
32
  }).then(runRecipe);
30
- };
31
- }
32
- function paralysis(list, fn, concurrency = Infinity) {
33
- if (!(typeof concurrency === "number" && concurrency >= 1)) {
34
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
35
33
  }
36
- const run = createRun(concurrency);
37
34
  return Promise.all(Array.from(list, (...args) => run([fn, args])));
38
35
  }
39
36
 
@@ -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 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 concurrency === \"number\" && concurrency >= 1)) {\n throw new TypeError(\"Expected `concurrency` to be a number from 1 and up\");\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;AAC7B,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,EAAE,OAAO,WAAA,KAAgB,QAAA,IAAY,eAAe,CAAA,CAAA,EAAI;AAC1D,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AACA,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;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\n\nexport function paralysis(list, fn, concurrency = Infinity) {\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 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 return new Promise((resolve) => {\n resolve(fn(...args));\n }).finally(release);\n }\n\n 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 return Promise.all(Array.from(list, (...args) => run([fn, args])));\n}\n"],"names":["fn"],"mappings":";;;;AAEO,SAAS,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI,WAAA,GAAc,QAAA,EAAU;AAC1D,EAAA,IAAI,EAAE,OAAO,WAAA,KAAgB,QAAA,IAAY,eAAe,CAAA,CAAA,EAAI;AAC1D,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AAEA,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,CAACA,GAAAA,EAAI,IAAI,CAAA,EAAG;AAC7B,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY;AAC9B,MAAA,OAAA,CAAQA,GAAAA,CAAG,GAAG,IAAI,CAAC,CAAA;AAAA,IACrB,CAAC,CAAA,CAAE,OAAA,CAAQ,OAAO,CAAA;AAAA,EACpB;AAEA,EAAA,SAAS,IAAI,MAAA,EAAQ;AAGnB,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;AAEA,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,6 +1,9 @@
1
1
  import TinyQueue from 'tinyqueue';
2
2
 
3
- function createRun(concurrency) {
3
+ function paralysis(list, fn, concurrency = Infinity) {
4
+ if (!(typeof concurrency === "number" && concurrency >= 1)) {
5
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
6
+ }
4
7
  const queue = new TinyQueue();
5
8
  let slots = Math.floor(concurrency);
6
9
  function release() {
@@ -12,12 +15,12 @@ function createRun(concurrency) {
12
15
  slots++;
13
16
  }
14
17
  }
15
- function runRecipe([fn, args]) {
18
+ function runRecipe([fn2, args]) {
16
19
  return new Promise((resolve) => {
17
- resolve(fn(...args));
20
+ resolve(fn2(...args));
18
21
  }).finally(release);
19
22
  }
20
- return function run(recipe) {
23
+ function run(recipe) {
21
24
  if (slots > 0) {
22
25
  slots--;
23
26
  return runRecipe(recipe);
@@ -25,13 +28,7 @@ function createRun(concurrency) {
25
28
  return new Promise((resolve) => {
26
29
  queue.push([resolve, recipe]);
27
30
  }).then(runRecipe);
28
- };
29
- }
30
- function paralysis(list, fn, concurrency = Infinity) {
31
- if (!(typeof concurrency === "number" && concurrency >= 1)) {
32
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
33
31
  }
34
- const run = createRun(concurrency);
35
32
  return Promise.all(Array.from(list, (...args) => run([fn, args])));
36
33
  }
37
34
 
@@ -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 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 concurrency === \"number\" && concurrency >= 1)) {\n throw new TypeError(\"Expected `concurrency` to be a number from 1 and up\");\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;AAC7B,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,EAAE,OAAO,WAAA,KAAgB,QAAA,IAAY,eAAe,CAAA,CAAA,EAAI;AAC1D,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AACA,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;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/paralysis.js"],"sourcesContent":["import TinyQueue from \"tinyqueue\";\n\nexport function paralysis(list, fn, concurrency = Infinity) {\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 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 return new Promise((resolve) => {\n resolve(fn(...args));\n }).finally(release);\n }\n\n 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 return Promise.all(Array.from(list, (...args) => run([fn, args])));\n}\n"],"names":["fn"],"mappings":";;AAEO,SAAS,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI,WAAA,GAAc,QAAA,EAAU;AAC1D,EAAA,IAAI,EAAE,OAAO,WAAA,KAAgB,QAAA,IAAY,eAAe,CAAA,CAAA,EAAI;AAC1D,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AAEA,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,CAACA,GAAAA,EAAI,IAAI,CAAA,EAAG;AAC7B,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY;AAC9B,MAAA,OAAA,CAAQA,GAAAA,CAAG,GAAG,IAAI,CAAC,CAAA;AAAA,IACrB,CAAC,CAAA,CAAE,OAAA,CAAQ,OAAO,CAAA;AAAA,EACpB;AAEA,EAAA,SAAS,IAAI,MAAA,EAAQ;AAGnB,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;AAEA,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paralysis",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Map over promises concurrently",
5
5
  "repository": "th3rius/paralysis",
6
6
  "keywords": [
@@ -18,7 +18,7 @@
18
18
  "scripts": {
19
19
  "prepare": "husky",
20
20
  "build": "rimraf dist && pkgroll --sourcemap",
21
- "test": "node --test --experimental-test-module-mocks **/*.spec.js"
21
+ "test": "node --test **/*.spec.js"
22
22
  },
23
23
  "main": "./dist/index.cjs",
24
24
  "module": "./dist/index.mjs",
package/src/paralysis.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import TinyQueue from "tinyqueue";
2
2
 
3
- function createRun(concurrency) {
3
+ export function paralysis(list, fn, concurrency = Infinity) {
4
+ if (!(typeof concurrency === "number" && concurrency >= 1)) {
5
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
6
+ }
7
+
4
8
  const queue = new TinyQueue();
5
9
  let slots = Math.floor(concurrency);
6
10
 
@@ -22,7 +26,7 @@ function createRun(concurrency) {
22
26
  }).finally(release);
23
27
  }
24
28
 
25
- return function run(recipe) {
29
+ function run(recipe) {
26
30
  // If we have an available slot, take the slot and return
27
31
  // a promise that executes the function immediately.
28
32
  if (slots > 0) {
@@ -36,13 +40,7 @@ function createRun(concurrency) {
36
40
  return new Promise((resolve) => {
37
41
  queue.push([resolve, recipe]);
38
42
  }).then(runRecipe);
39
- };
40
- }
41
-
42
- export function paralysis(list, fn, concurrency = Infinity) {
43
- if (!(typeof concurrency === "number" && concurrency >= 1)) {
44
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
45
43
  }
46
- const run = createRun(concurrency);
44
+
47
45
  return Promise.all(Array.from(list, (...args) => run([fn, args])));
48
46
  }