update modules

This commit is contained in:
Joel Male
2022-11-10 20:43:16 +10:00
parent c9072d53a3
commit 29d4f522f2
5233 changed files with 476623 additions and 533020 deletions
+53 -24
View File
@@ -1,42 +1,71 @@
'use strict';
const pTry = require('p-try');
const Queue = require('yocto-queue');
module.exports = concurrency => {
if (concurrency < 1) {
const pLimit = concurrency => {
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
}
const queue = [];
const queue = new Queue();
let activeCount = 0;
const next = () => {
activeCount--;
if (queue.length > 0) {
queue.shift()();
if (queue.size > 0) {
queue.dequeue()();
}
};
return fn => new Promise((resolve, reject) => {
const run = () => {
activeCount++;
const run = async (fn, resolve, ...args) => {
activeCount++;
pTry(fn).then(
val => {
resolve(val);
next();
},
err => {
reject(err);
next();
}
);
};
const result = (async () => fn(...args))();
if (activeCount < concurrency) {
run();
} else {
queue.push(run);
resolve(result);
try {
await result;
} catch {}
next();
};
const enqueue = (fn, resolve, ...args) => {
queue.enqueue(run.bind(null, fn, resolve, ...args));
(async () => {
// This function needs to wait until the next microtask before comparing
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
// when the run function is dequeued and called. The comparison in the if-statement
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
await Promise.resolve();
if (activeCount < concurrency && queue.size > 0) {
queue.dequeue()();
}
})();
};
const generator = (fn, ...args) => new Promise(resolve => {
enqueue(fn, resolve, ...args);
});
Object.defineProperties(generator, {
activeCount: {
get: () => activeCount
},
pendingCount: {
get: () => queue.size
},
clearQueue: {
value: () => {
queue.clear();
}
}
});
return generator;
};
module.exports = pLimit;
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+15 -12
View File
@@ -1,22 +1,24 @@
{
"name": "p-limit",
"version": "1.3.0",
"version": "3.1.0",
"description": "Run multiple promise-returning & async functions with limited concurrency",
"license": "MIT",
"repository": "sindresorhus/p-limit",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=4"
"node": ">=10"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"promise",
@@ -36,14 +38,15 @@
"bluebird"
],
"dependencies": {
"p-try": "^1.0.0"
"yocto-queue": "^0.1.0"
},
"devDependencies": {
"ava": "*",
"delay": "^2.0.0",
"in-range": "^1.0.0",
"random-int": "^1.0.0",
"time-span": "^2.0.0",
"xo": "*"
"ava": "^2.4.0",
"delay": "^4.4.0",
"in-range": "^2.0.0",
"random-int": "^2.0.1",
"time-span": "^4.0.0",
"tsd": "^0.13.1",
"xo": "^0.35.0"
}
}
+43 -11
View File
@@ -1,15 +1,13 @@
# p-limit [![Build Status](https://travis-ci.org/sindresorhus/p-limit.svg?branch=master)](https://travis-ci.org/sindresorhus/p-limit)
# p-limit
> Run multiple promise-returning & async functions with limited concurrency
## Install
```
$ npm install p-limit
```
## Usage
```js
@@ -30,7 +28,6 @@ const input = [
})();
```
## API
### pLimit(concurrency)
@@ -39,14 +36,15 @@ Returns a `limit` function.
#### concurrency
Type: `number`<br>
Minimum: `1`
Type: `number`\
Minimum: `1`\
Default: `Infinity`
Concurrency limit.
### limit(fn)
### limit(fn, ...args)
Returns the promise returned by calling `fn`.
Returns the promise returned by calling `fn(...args)`.
#### fn
@@ -54,6 +52,33 @@ Type: `Function`
Promise-returning/async function.
#### args
Any arguments to pass through to `fn`.
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.
### limit.activeCount
The number of promises that are currently running.
### limit.pendingCount
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
### limit.clearQueue()
Discard pending promises that are waiting to run.
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.
Note: This does not cancel promises that are already running.
## FAQ
### How is this different from the [`p-queue`](https://github.com/sindresorhus/p-queue) package?
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.
## Related
@@ -63,7 +88,14 @@ Promise-returning/async function.
- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
- [More…](https://github.com/sindresorhus/promise-fun)
---
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
<div align="center">
<b>
<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>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>