Initial commit: New MoreminiMore website with fresh design
This commit is contained in:
136
node_modules/p-limit/index.d.ts
generated
vendored
Normal file
136
node_modules/p-limit/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
export type LimitFunction = {
|
||||
/**
|
||||
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;
|
||||
|
||||
/**
|
||||
Get or set the concurrency limit.
|
||||
*/
|
||||
concurrency: 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.
|
||||
|
||||
When `rejectOnClear` is enabled, pending promises are rejected with an `AbortError`.
|
||||
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
||||
*/
|
||||
clearQueue: () => void;
|
||||
|
||||
/**
|
||||
Process an iterable of inputs with limited concurrency.
|
||||
|
||||
The mapper function receives the item value and its index.
|
||||
|
||||
This is a convenience function for processing inputs that arrive in batches. For more complex use cases, see [p-map](https://github.com/sindresorhus/p-map).
|
||||
|
||||
@param iterable - An iterable containing an argument for the given function.
|
||||
@param mapperFunction - Promise-returning/async function.
|
||||
@returns A promise equivalent to `Promise.all(Array.from(iterable, (item, index) => limit(mapperFunction, item, index)))`.
|
||||
*/
|
||||
map: <Input, ReturnType> (
|
||||
iterable: Iterable<Input>,
|
||||
mapperFunction: (input: Input, index: number) => PromiseLike<ReturnType> | ReturnType
|
||||
) => Promise<ReturnType[]>;
|
||||
|
||||
/**
|
||||
@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.
|
||||
|
||||
Warning: Avoid calling the same `limit` function inside a function that is already limited by it. This can create a deadlock where inner tasks never run. Use a separate limiter for inner tasks.
|
||||
|
||||
@returns The promise returned by calling `fn(...arguments)`.
|
||||
*/
|
||||
<Arguments extends unknown[], ReturnType>(
|
||||
function_: (...arguments_: Arguments) => PromiseLike<ReturnType> | ReturnType,
|
||||
...arguments_: Arguments
|
||||
): Promise<ReturnType>;
|
||||
};
|
||||
|
||||
/**
|
||||
Run multiple promise-returning & async functions with limited concurrency.
|
||||
|
||||
@param concurrency - Concurrency limit. Minimum: `1`. You can pass a number or an options object with a `concurrency` property.
|
||||
@returns A `limit` function.
|
||||
|
||||
@example
|
||||
```
|
||||
import pLimit from 'p-limit';
|
||||
|
||||
const limit = pLimit(1);
|
||||
|
||||
const input = [
|
||||
limit(() => fetchSomething('foo')),
|
||||
limit(() => fetchSomething('bar')),
|
||||
limit(() => doSomething())
|
||||
];
|
||||
|
||||
// Only one promise is run at once
|
||||
const result = await Promise.all(input);
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import pLimit from 'p-limit';
|
||||
|
||||
const limit = pLimit({concurrency: 1});
|
||||
```
|
||||
*/
|
||||
export default function pLimit(concurrency: number | Options): LimitFunction;
|
||||
|
||||
export type Options = {
|
||||
/**
|
||||
Concurrency limit.
|
||||
|
||||
Minimum: `1`.
|
||||
*/
|
||||
readonly concurrency: number;
|
||||
|
||||
/**
|
||||
Reject pending promises with an `AbortError` when `clearQueue()` is called.
|
||||
|
||||
Default: `false`.
|
||||
|
||||
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
||||
*/
|
||||
readonly rejectOnClear?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns a function with limited concurrency.
|
||||
|
||||
The returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.
|
||||
|
||||
Ideal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.
|
||||
|
||||
@param function_ - Promise-returning/async function.
|
||||
@return Function with limited concurrency.
|
||||
|
||||
@example
|
||||
```
|
||||
import {limitFunction} from 'p-limit';
|
||||
|
||||
const limitedFunction = limitFunction(async () => {
|
||||
return doSomething();
|
||||
}, {concurrency: 1});
|
||||
|
||||
const input = Array.from({length: 10}, limitedFunction);
|
||||
|
||||
// Only one promise is run at once.
|
||||
await Promise.all(input);
|
||||
```
|
||||
*/
|
||||
export function limitFunction<Arguments extends unknown[], ReturnType>(
|
||||
function_: (...arguments_: Arguments) => PromiseLike<ReturnType>,
|
||||
options: Options
|
||||
): (...arguments_: Arguments) => Promise<ReturnType>;
|
||||
127
node_modules/p-limit/index.js
generated
vendored
Normal file
127
node_modules/p-limit/index.js
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
import Queue from 'yocto-queue';
|
||||
|
||||
export default function pLimit(concurrency) {
|
||||
let rejectOnClear = false;
|
||||
|
||||
if (typeof concurrency === 'object') {
|
||||
({concurrency, rejectOnClear = false} = concurrency);
|
||||
}
|
||||
|
||||
validateConcurrency(concurrency);
|
||||
|
||||
if (typeof rejectOnClear !== 'boolean') {
|
||||
throw new TypeError('Expected `rejectOnClear` to be a boolean');
|
||||
}
|
||||
|
||||
const queue = new Queue();
|
||||
let activeCount = 0;
|
||||
|
||||
const resumeNext = () => {
|
||||
// Process the next queued function if we're under the concurrency limit
|
||||
if (activeCount < concurrency && queue.size > 0) {
|
||||
activeCount++;
|
||||
queue.dequeue().run();
|
||||
}
|
||||
};
|
||||
|
||||
const next = () => {
|
||||
activeCount--;
|
||||
resumeNext();
|
||||
};
|
||||
|
||||
const run = async (function_, resolve, arguments_) => {
|
||||
// Execute the function and capture the result promise
|
||||
const result = (async () => function_(...arguments_))();
|
||||
|
||||
// Resolve immediately with the promise (don't wait for completion)
|
||||
resolve(result);
|
||||
|
||||
// Wait for the function to complete (success or failure)
|
||||
// We catch errors here to prevent unhandled rejections,
|
||||
// but the original promise rejection is preserved for the caller
|
||||
try {
|
||||
await result;
|
||||
} catch {}
|
||||
|
||||
// Decrement active count and process next queued function
|
||||
next();
|
||||
};
|
||||
|
||||
const enqueue = (function_, resolve, reject, arguments_) => {
|
||||
const queueItem = {reject};
|
||||
|
||||
// Queue the internal resolve function instead of the run function
|
||||
// to preserve the asynchronous execution context.
|
||||
new Promise(internalResolve => { // eslint-disable-line promise/param-names
|
||||
queueItem.run = internalResolve;
|
||||
queue.enqueue(queueItem);
|
||||
}).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then
|
||||
|
||||
// Start processing immediately if we haven't reached the concurrency limit
|
||||
if (activeCount < concurrency) {
|
||||
resumeNext();
|
||||
}
|
||||
};
|
||||
|
||||
const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
|
||||
enqueue(function_, resolve, reject, arguments_);
|
||||
});
|
||||
|
||||
Object.defineProperties(generator, {
|
||||
activeCount: {
|
||||
get: () => activeCount,
|
||||
},
|
||||
pendingCount: {
|
||||
get: () => queue.size,
|
||||
},
|
||||
clearQueue: {
|
||||
value() {
|
||||
if (!rejectOnClear) {
|
||||
queue.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
const abortError = AbortSignal.abort().reason;
|
||||
|
||||
while (queue.size > 0) {
|
||||
queue.dequeue().reject(abortError);
|
||||
}
|
||||
},
|
||||
},
|
||||
concurrency: {
|
||||
get: () => concurrency,
|
||||
|
||||
set(newConcurrency) {
|
||||
validateConcurrency(newConcurrency);
|
||||
concurrency = newConcurrency;
|
||||
|
||||
queueMicrotask(() => {
|
||||
// eslint-disable-next-line no-unmodified-loop-condition
|
||||
while (activeCount < concurrency && queue.size > 0) {
|
||||
resumeNext();
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
map: {
|
||||
async value(iterable, function_) {
|
||||
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
||||
return Promise.all(promises);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
export function limitFunction(function_, options) {
|
||||
const limit = pLimit(options);
|
||||
|
||||
return (...arguments_) => limit(() => function_(...arguments_));
|
||||
}
|
||||
|
||||
function validateConcurrency(concurrency) {
|
||||
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
||||
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
||||
}
|
||||
}
|
||||
9
node_modules/p-limit/license
generated
vendored
Normal file
9
node_modules/p-limit/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
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:
|
||||
|
||||
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.
|
||||
58
node_modules/p-limit/package.json
generated
vendored
Normal file
58
node_modules/p-limit/package.json
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "p-limit",
|
||||
"version": "7.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": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd",
|
||||
"benchmark": "node benchmark.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"promise",
|
||||
"limit",
|
||||
"limited",
|
||||
"concurrency",
|
||||
"throttle",
|
||||
"throat",
|
||||
"rate",
|
||||
"batch",
|
||||
"ratelimit",
|
||||
"task",
|
||||
"queue",
|
||||
"async",
|
||||
"await",
|
||||
"promises",
|
||||
"bluebird"
|
||||
],
|
||||
"dependencies": {
|
||||
"yocto-queue": "^1.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^6.4.1",
|
||||
"in-range": "^3.0.0",
|
||||
"random-int": "^3.0.0",
|
||||
"time-span": "^5.1.0",
|
||||
"tsd": "^0.33.0",
|
||||
"xo": "^1.2.1"
|
||||
}
|
||||
}
|
||||
173
node_modules/p-limit/readme.md
generated
vendored
Normal file
173
node_modules/p-limit/readme.md
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
# p-limit
|
||||
|
||||
> Run multiple promise-returning & async functions with limited concurrency
|
||||
|
||||
*Works in Node.js and browsers.*
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install p-limit
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import pLimit from 'p-limit';
|
||||
|
||||
const limit = pLimit(1);
|
||||
|
||||
const input = [
|
||||
limit(() => fetchSomething('foo')),
|
||||
limit(() => fetchSomething('bar')),
|
||||
limit(() => doSomething())
|
||||
];
|
||||
|
||||
// Only one promise is run at once
|
||||
const result = await Promise.all(input);
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### pLimit(concurrency) <sup>default export</sup>
|
||||
|
||||
Returns a `limit` function.
|
||||
|
||||
#### concurrency
|
||||
|
||||
Type: `number | object`\
|
||||
Minimum: `1`
|
||||
|
||||
Concurrency limit.
|
||||
|
||||
You can pass a number or an options object with a `concurrency` property.
|
||||
|
||||
#### rejectOnClear
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Reject pending promises with an `AbortError` when `clearQueue()` is called.
|
||||
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
||||
|
||||
```js
|
||||
import pLimit from 'p-limit';
|
||||
|
||||
const limit = pLimit({concurrency: 1});
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
Warning: Avoid calling the same `limit` function inside a function that is already limited by it. This can create a deadlock where inner tasks never run. Use a separate limiter for inner tasks.
|
||||
|
||||
### limit.map(iterable, mapperFunction)
|
||||
|
||||
Process an iterable of inputs with limited concurrency.
|
||||
|
||||
The mapper function receives the item value and its index.
|
||||
|
||||
Returns a promise equivalent to `Promise.all(Array.from(iterable, (item, index) => limit(mapperFunction, item, index)))`.
|
||||
|
||||
This is a convenience function for processing inputs that arrive in batches. For more complex use cases, see [p-map](https://github.com/sindresorhus/p-map).
|
||||
|
||||
### 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.
|
||||
|
||||
When `rejectOnClear` is enabled, pending promises are rejected with an `AbortError`.
|
||||
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
||||
|
||||
### limit.concurrency
|
||||
|
||||
Get or set the concurrency limit.
|
||||
|
||||
### limitFunction(fn, options) <sup>named export</sup>
|
||||
|
||||
Returns a function with limited concurrency.
|
||||
|
||||
The returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.
|
||||
|
||||
Ideal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.
|
||||
|
||||
```js
|
||||
import {limitFunction} from 'p-limit';
|
||||
|
||||
const limitedFunction = limitFunction(async () => {
|
||||
return doSomething();
|
||||
}, {concurrency: 1});
|
||||
|
||||
const input = Array.from({length: 10}, limitedFunction);
|
||||
|
||||
// Only one promise is run at once.
|
||||
await Promise.all(input);
|
||||
```
|
||||
|
||||
#### fn
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Promise-returning/async function.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
#### concurrency
|
||||
|
||||
Type: `number`\
|
||||
Minimum: `1`
|
||||
|
||||
Concurrency limit.
|
||||
|
||||
#### rejectOnClear
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Reject pending promises with an `AbortError` when `clearQueue()` is called.
|
||||
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
||||
|
||||
## Recipes
|
||||
|
||||
See [recipes.md](recipes.md) for common use cases and patterns.
|
||||
|
||||
## 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-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-map](https://github.com/sindresorhus/p-map) - Run promise-returning & async functions concurrently with different inputs
|
||||
- [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)
|
||||
Reference in New Issue
Block a user