aboutsummaryrefslogtreecommitdiff
path: root/node_modules/p-limit
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/p-limit')
-rw-r--r--node_modules/p-limit/index.d.ts38
-rw-r--r--node_modules/p-limit/index.js57
-rw-r--r--node_modules/p-limit/license9
-rw-r--r--node_modules/p-limit/package.json52
-rw-r--r--node_modules/p-limit/readme.md101
5 files changed, 257 insertions, 0 deletions
diff --git a/node_modules/p-limit/index.d.ts b/node_modules/p-limit/index.d.ts
new file mode 100644
index 0000000..6bbfad4
--- /dev/null
+++ b/node_modules/p-limit/index.d.ts
@@ -0,0 +1,38 @@
+export interface Limit {
+ /**
+ @param fn - Promise-returning/async function.
+ @param arguments - 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.
+ @returns The promise returned by calling `fn(...arguments)`.
+ */
+ <Arguments extends unknown[], ReturnType>(
+ fn: (...arguments: Arguments) => PromiseLike<ReturnType> | ReturnType,
+ ...arguments: Arguments
+ ): Promise<ReturnType>;
+
+ /**
+ The number of promises that are currently running.
+ */
+ readonly activeCount: number;
+
+ /**
+ The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
+ */
+ readonly pendingCount: number;
+
+ /**
+ 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.
+ */
+ clearQueue(): void;
+}
+
+/**
+Run multiple promise-returning & async functions with limited concurrency.
+
+@param concurrency - Concurrency limit. Minimum: `1`.
+@returns A `limit` function.
+*/
+export default function pLimit(concurrency: number): Limit;
diff --git a/node_modules/p-limit/index.js b/node_modules/p-limit/index.js
new file mode 100644
index 0000000..6a72a4c
--- /dev/null
+++ b/node_modules/p-limit/index.js
@@ -0,0 +1,57 @@
+'use strict';
+const pTry = require('p-try');
+
+const pLimit = concurrency => {
+ if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
+ return Promise.reject(new TypeError('Expected `concurrency` to be a number from 1 and up'));
+ }
+
+ const queue = [];
+ let activeCount = 0;
+
+ const next = () => {
+ activeCount--;
+
+ if (queue.length > 0) {
+ queue.shift()();
+ }
+ };
+
+ const run = (fn, resolve, ...args) => {
+ activeCount++;
+
+ const result = pTry(fn, ...args);
+
+ resolve(result);
+
+ result.then(next, next);
+ };
+
+ const enqueue = (fn, resolve, ...args) => {
+ if (activeCount < concurrency) {
+ run(fn, resolve, ...args);
+ } else {
+ queue.push(run.bind(null, fn, resolve, ...args));
+ }
+ };
+
+ const generator = (fn, ...args) => new Promise(resolve => enqueue(fn, resolve, ...args));
+ Object.defineProperties(generator, {
+ activeCount: {
+ get: () => activeCount
+ },
+ pendingCount: {
+ get: () => queue.length
+ },
+ clearQueue: {
+ value: () => {
+ queue.length = 0;
+ }
+ }
+ });
+
+ return generator;
+};
+
+module.exports = pLimit;
+module.exports.default = pLimit;
diff --git a/node_modules/p-limit/license b/node_modules/p-limit/license
new file mode 100644
index 0000000..e7af2f7
--- /dev/null
+++ b/node_modules/p-limit/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/p-limit/package.json b/node_modules/p-limit/package.json
new file mode 100644
index 0000000..99a814f
--- /dev/null
+++ b/node_modules/p-limit/package.json
@@ -0,0 +1,52 @@
+{
+ "name": "p-limit",
+ "version": "2.3.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"
+ },
+ "engines": {
+ "node": ">=6"
+ },
+ "scripts": {
+ "test": "xo && ava && tsd-check"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "keywords": [
+ "promise",
+ "limit",
+ "limited",
+ "concurrency",
+ "throttle",
+ "throat",
+ "rate",
+ "batch",
+ "ratelimit",
+ "task",
+ "queue",
+ "async",
+ "await",
+ "promises",
+ "bluebird"
+ ],
+ "dependencies": {
+ "p-try": "^2.0.0"
+ },
+ "devDependencies": {
+ "ava": "^1.2.1",
+ "delay": "^4.1.0",
+ "in-range": "^1.0.0",
+ "random-int": "^1.0.0",
+ "time-span": "^2.0.0",
+ "tsd-check": "^0.3.0",
+ "xo": "^0.24.0"
+ }
+}
diff --git a/node_modules/p-limit/readme.md b/node_modules/p-limit/readme.md
new file mode 100644
index 0000000..64aa476
--- /dev/null
+++ b/node_modules/p-limit/readme.md
@@ -0,0 +1,101 @@
+# p-limit [![Build Status](https://travis-ci.org/sindresorhus/p-limit.svg?branch=master)](https://travis-ci.org/sindresorhus/p-limit)
+
+> Run multiple promise-returning & async functions with limited concurrency
+
+## Install
+
+```
+$ npm install p-limit
+```
+
+## Usage
+
+```js
+const pLimit = require('p-limit');
+
+const limit = pLimit(1);
+
+const input = [
+ limit(() => fetchSomething('foo')),
+ limit(() => fetchSomething('bar')),
+ limit(() => doSomething())
+];
+
+(async () => {
+ // Only one promise is run at once
+ const result = await Promise.all(input);
+ console.log(result);
+})();
+```
+
+## API
+
+### pLimit(concurrency)
+
+Returns a `limit` function.
+
+#### concurrency
+
+Type: `number`\
+Minimum: `1`\
+Default: `Infinity`
+
+Concurrency limit.
+
+### limit(fn, ...args)
+
+Returns the promise returned by calling `fn(...args)`.
+
+#### fn
+
+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
+
+- [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
+- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning & async functions
+- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
+- [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)
+
+---
+
+<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>