@common.js/p-limit 4.0.0 → 5.0.0

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  The [p-limit](https://www.npmjs.com/package/p-limit) package exported as CommonJS modules.
4
4
 
5
- Exported from [p-limit@4.0.0](https://www.npmjs.com/package/p-limit/v/4.0.0) using https://github.com/etienne-martin/common.js.
5
+ Exported from [p-limit@5.0.0](https://www.npmjs.com/package/p-limit/v/5.0.0) using https://github.com/etienne-martin/common.js.
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ AsyncResource: function() {
13
+ return AsyncResource;
14
+ },
15
+ AsyncLocalStorage: function() {
16
+ return AsyncLocalStorage;
17
+ }
18
+ });
19
+ function _classCallCheck(instance, Constructor) {
20
+ if (!(instance instanceof Constructor)) {
21
+ throw new TypeError("Cannot call a class as a function");
22
+ }
23
+ }
24
+ function _defineProperties(target, props) {
25
+ for(var i = 0; i < props.length; i++){
26
+ var descriptor = props[i];
27
+ descriptor.enumerable = descriptor.enumerable || false;
28
+ descriptor.configurable = true;
29
+ if ("value" in descriptor) descriptor.writable = true;
30
+ Object.defineProperty(target, descriptor.key, descriptor);
31
+ }
32
+ }
33
+ function _createClass(Constructor, protoProps, staticProps) {
34
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
35
+ if (staticProps) _defineProperties(Constructor, staticProps);
36
+ return Constructor;
37
+ }
38
+ var AsyncResource = {
39
+ bind: function bind(fn, _type, thisArg) {
40
+ return fn.bind(thisArg);
41
+ }
42
+ };
43
+ var AsyncLocalStorage = /*#__PURE__*/ function() {
44
+ "use strict";
45
+ function AsyncLocalStorage() {
46
+ _classCallCheck(this, AsyncLocalStorage);
47
+ }
48
+ _createClass(AsyncLocalStorage, [
49
+ {
50
+ key: "getStore",
51
+ value: function getStore() {
52
+ return undefined;
53
+ }
54
+ },
55
+ {
56
+ key: "run",
57
+ value: function run(_store, callback) {
58
+ return callback();
59
+ }
60
+ }
61
+ ]);
62
+ return AsyncLocalStorage;
63
+ }();
package/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- /* eslint-disable @typescript-eslint/member-ordering */
2
-
3
- export interface LimitFunction {
1
+ export type LimitFunction = {
4
2
  /**
5
3
  The number of promises that are currently running.
6
4
  */
@@ -26,10 +24,10 @@ export interface LimitFunction {
26
24
  @returns The promise returned by calling `fn(...arguments)`.
27
25
  */
28
26
  <Arguments extends unknown[], ReturnType>(
29
- fn: (...arguments: Arguments) => PromiseLike<ReturnType> | ReturnType,
30
- ...arguments: Arguments
27
+ fn: (...arguments_: Arguments) => PromiseLike<ReturnType> | ReturnType,
28
+ ...arguments_: Arguments
31
29
  ): Promise<ReturnType>;
32
- }
30
+ };
33
31
 
34
32
  /**
35
33
  Run multiple promise-returning & async functions with limited concurrency.
package/index.js CHANGED
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _yoctoQueue = /*#__PURE__*/ _interopRequireDefault(require("yocto-queue"));
12
+ var _asyncHooks = require("#async_hooks");
12
13
  function _arrayLikeToArray(arr, len) {
13
14
  if (len == null || len > arr.length) len = arr.length;
14
15
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -176,7 +177,7 @@ function pLimit(concurrency) {
176
177
  }
177
178
  };
178
179
  var run = function() {
179
- var _ref = _asyncToGenerator(function(fn, resolve, args) {
180
+ var _ref = _asyncToGenerator(function(function_, resolve, arguments_) {
180
181
  var result, e;
181
182
  return __generator(this, function(_state) {
182
183
  switch(_state.label){
@@ -186,7 +187,7 @@ function pLimit(concurrency) {
186
187
  return __generator(this, function(_state) {
187
188
  return [
188
189
  2,
189
- fn.apply(void 0, _toConsumableArray(args))
190
+ function_.apply(void 0, _toConsumableArray(arguments_))
190
191
  ];
191
192
  });
192
193
  })();
@@ -223,12 +224,12 @@ function pLimit(concurrency) {
223
224
  }
224
225
  });
225
226
  });
226
- return function run(fn, resolve, args) {
227
+ return function run(function_, resolve, arguments_) {
227
228
  return _ref.apply(this, arguments);
228
229
  };
229
230
  }();
230
- var enqueue = function(fn, resolve, args) {
231
- queue.enqueue(run.bind(undefined, fn, resolve, args));
231
+ var enqueue = function(function_, resolve, arguments_) {
232
+ queue.enqueue(_asyncHooks.AsyncResource.bind(run.bind(undefined, function_, resolve, arguments_)));
232
233
  _asyncToGenerator(function() {
233
234
  return __generator(this, function(_state) {
234
235
  switch(_state.label){
@@ -253,12 +254,12 @@ function pLimit(concurrency) {
253
254
  });
254
255
  })();
255
256
  };
256
- var generator = function(fn) {
257
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
258
- args[_key - 1] = arguments[_key];
257
+ var generator = function(function_) {
258
+ for(var _len = arguments.length, arguments_ = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
259
+ arguments_[_key - 1] = arguments[_key];
259
260
  }
260
261
  return new Promise(function(resolve) {
261
- enqueue(fn, resolve, args);
262
+ enqueue(function_, resolve, arguments_);
262
263
  });
263
264
  };
264
265
  Object.defineProperties(generator, {
@@ -273,7 +274,7 @@ function pLimit(concurrency) {
273
274
  }
274
275
  },
275
276
  clearQueue: {
276
- value: function() {
277
+ value: function value() {
277
278
  queue.clear();
278
279
  }
279
280
  }
package/package.json CHANGED
@@ -1,33 +1,41 @@
1
1
  {
2
2
  "name": "@common.js/p-limit",
3
- "version": "4.0.0",
4
- "description": "Run multiple promise-returning & async functions with limited concurrency",
3
+ "version": "5.0.0",
4
+ "description": "p-limit package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",
7
7
  "funding": "https://github.com/sponsors/sindresorhus",
8
8
  "type": "commonjs",
9
+ "imports": {
10
+ "#async_hooks": {
11
+ "node": "async_hooks",
12
+ "default": "./async-hooks-stub.js"
13
+ }
14
+ },
9
15
  "engines": {
10
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
16
+ "node": ">=18"
11
17
  },
12
18
  "scripts": {
13
19
  "test": "xo && ava && tsd"
14
20
  },
15
21
  "files": [
16
22
  "index.js",
17
- "index.d.ts"
23
+ "index.d.ts",
24
+ "async-hooks-stub.js"
18
25
  ],
19
26
  "dependencies": {
20
27
  "@common.js/yocto-queue": "^1.0.0"
21
28
  },
22
29
  "devDependencies": {
23
- "ava": "^3.15.0",
24
- "delay": "^5.0.0",
30
+ "ava": "^5.3.1",
31
+ "delay": "^6.0.0",
25
32
  "in-range": "^3.0.0",
26
33
  "random-int": "^3.0.0",
27
- "time-span": "^5.0.0",
28
- "tsd": "^0.17.0",
29
- "xo": "^0.44.0"
34
+ "time-span": "^5.1.0",
35
+ "tsd": "^0.29.0",
36
+ "xo": "^0.56.0"
30
37
  },
31
38
  "homepage": "https://github.com/etienne-martin/common.js#readme",
39
+ "types": "./index.d.ts",
32
40
  "main": "./index.js"
33
41
  }
package/readme.md DELETED
@@ -1,99 +0,0 @@
1
- # p-limit
2
-
3
- > Run multiple promise-returning & async functions with limited concurrency
4
-
5
- ## Install
6
-
7
- ```
8
- $ npm install p-limit
9
- ```
10
-
11
- ## Usage
12
-
13
- ```js
14
- import pLimit from 'p-limit';
15
-
16
- const limit = pLimit(1);
17
-
18
- const input = [
19
- limit(() => fetchSomething('foo')),
20
- limit(() => fetchSomething('bar')),
21
- limit(() => doSomething())
22
- ];
23
-
24
- // Only one promise is run at once
25
- const result = await Promise.all(input);
26
- console.log(result);
27
- ```
28
-
29
- ## API
30
-
31
- ### pLimit(concurrency)
32
-
33
- Returns a `limit` function.
34
-
35
- #### concurrency
36
-
37
- Type: `number`\
38
- Minimum: `1`\
39
- Default: `Infinity`
40
-
41
- Concurrency limit.
42
-
43
- ### limit(fn, ...args)
44
-
45
- Returns the promise returned by calling `fn(...args)`.
46
-
47
- #### fn
48
-
49
- Type: `Function`
50
-
51
- Promise-returning/async function.
52
-
53
- #### args
54
-
55
- Any arguments to pass through to `fn`.
56
-
57
- Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.
58
-
59
- ### limit.activeCount
60
-
61
- The number of promises that are currently running.
62
-
63
- ### limit.pendingCount
64
-
65
- The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
66
-
67
- ### limit.clearQueue()
68
-
69
- Discard pending promises that are waiting to run.
70
-
71
- This might be useful if you want to teardown the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.
72
-
73
- Note: This does not cancel promises that are already running.
74
-
75
- ## FAQ
76
-
77
- ### How is this different from the [`p-queue`](https://github.com/sindresorhus/p-queue) package?
78
-
79
- This package is only about limiting the number of concurrent executions, while `p-queue` is a fully featured queue implementation with lots of different options, introspection, and ability to pause the queue.
80
-
81
- ## Related
82
-
83
- - [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
84
- - [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning & async functions
85
- - [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
86
- - [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
87
- - [More…](https://github.com/sindresorhus/promise-fun)
88
-
89
- ---
90
-
91
- <div align="center">
92
- <b>
93
- <a href="https://tidelift.com/subscription/pkg/npm-p-limit?utm_source=npm-p-limit&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
94
- </b>
95
- <br>
96
- <sub>
97
- Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
98
- </sub>
99
- </div>