1 |
3a515b92
|
cagy
|
export interface Limit {
|
2 |
|
|
/**
|
3 |
|
|
@param fn - Promise-returning/async function.
|
4 |
|
|
@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.
|
5 |
|
|
@returns The promise returned by calling `fn(...arguments)`.
|
6 |
|
|
*/
|
7 |
|
|
<Arguments extends unknown[], ReturnType>(
|
8 |
|
|
fn: (...arguments: Arguments) => PromiseLike<ReturnType> | ReturnType,
|
9 |
|
|
...arguments: Arguments
|
10 |
|
|
): Promise<ReturnType>;
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
The number of promises that are currently running.
|
14 |
|
|
*/
|
15 |
|
|
readonly activeCount: number;
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
|
19 |
|
|
*/
|
20 |
|
|
readonly pendingCount: number;
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
Discard pending promises that are waiting to run.
|
24 |
|
|
|
25 |
|
|
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.
|
26 |
|
|
|
27 |
|
|
Note: This does not cancel promises that are already running.
|
28 |
|
|
*/
|
29 |
|
|
clearQueue(): void;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
/**
|
33 |
|
|
Run multiple promise-returning & async functions with limited concurrency.
|
34 |
|
|
|
35 |
|
|
@param concurrency - Concurrency limit. Minimum: `1`.
|
36 |
|
|
@returns A `limit` function.
|
37 |
|
|
*/
|
38 |
|
|
export default function pLimit(concurrency: number): Limit;
|