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