UNPKG

3.24 kBTypeScriptView Raw
1// Last module patch version validated against: 3.0.7
2
3/**
4 * A d3-queue queue object as returned by queue(...)
5 */
6export interface Queue {
7 /**
8 * Adds the specified asynchronous task callback to the queue, with any optional arguments.
9 *
10 * @param task Task to be executed.The task is a function that will be called when the task should start.
11 * It is passed the specified optional arguments and an additional callback as the last argument;
12 * the callback must be invoked by the task when it finishes.
13 * The task must invoke the callback with two arguments: the error, if any, and the result of the task.
14 * To return multiple results from a single callback, wrap the results in an object or array.
15 * @param args Additional, optional arguments to be passed into deferred task on invocation.
16 * @throws If called after an `await`, will throw an `Error`.
17 */
18 defer(task: (...args: any[]) => void, ...args: any[]): this;
19
20 /**
21 * Aborts any active tasks, invoking each active task’s task.abort function, if any.
22 * Also prevents any new tasks from starting, and immediately invokes the queue.await or
23 * queue.awaitAll callback with an error indicating that the queue was aborted.
24 */
25 abort(): this;
26
27 /**
28 * Sets the callback to be invoked when all deferred tasks have finished (individual result arguments).
29 *
30 * @param callback Callback function to be executed, when error occurred or all deferred tasks have completed.
31 * The first argument to the callback is the first error that occurred, or null if no error occurred.
32 * If an error occurred, there are no additional arguments to the callback.
33 * Otherwise, the callback is passed each result as an additional argument.
34 * @throws If called several times or after `awaitAll`, will throw an `Error`.
35 */
36 await(callback: (error: any | null, ...results: any[]) => void): this;
37
38 /**
39 * Sets the callback to be invoked when all deferred tasks have finished (results array).
40 *
41 * @param callback Callback function to be executed, when error occurred or all deferred tasks have completed.
42 * The first argument to the callback is the first error that occurred, or null if no error occurred.
43 * If an error occurred, there are no additional arguments to the callback.
44 * Otherwise, the callback is also passed an array of results as the second argument.
45 * @throws If called several times or after `await`, will throw an `Error`.
46 */
47 awaitAll(callback: (error: any | null, results?: any[]) => void): this;
48}
49
50/**
51 * Construct a new queue with the specified concurrency. If concurrency is not specified, the queue has infinite concurrency.
52 * Otherwise, concurrency is a positive integer. For example, if concurrency is 1, then all tasks will be run in series.
53 * If concurrency is 3, then at most three tasks will be allowed to proceed concurrently; this is useful, for example,
54 * when loading resources in a web browser.
55 *
56 * @param concurrency Maximum number of deferred tasks to execute concurrently.
57 * @throws If `concurrency` is negative or zero, will throw an `Error`.
58 */
59export function queue(concurrency?: number): Queue;