UNPKG

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