UNPKG

26.7 kBTypeScriptView Raw
1// Type definitions for Async 3.2
2// Project: https://github.com/caolan/async, https://caolan.github.io/async
3// Definitions by: Boris Yankov <https://github.com/borisyankov>
4// Arseniy Maximov <https://github.com/kern0>
5// Angus Fenying <https://github.com/fenying>
6// Pascal Martin <https://github.com/pascalmartin>
7// Etienne Rossignon <https://github.com/erossignon>
8// Lifeng Zhu <https://github.com/Juliiii>
9// Tümay Çeber <https://github.com/brendtumi>
10// Andrew Pensinger <https://github.com/apnsngr>
11// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
12// TypeScript Version: 2.3
13
14export as namespace async;
15
16export interface Dictionary<T> { [key: string]: T; }
17export type IterableCollection<T> = T[] | IterableIterator<T> | AsyncIterable<T> | Dictionary<T>;
18
19export interface ErrorCallback<E = Error> { (err?: E | null): void; }
20export interface AsyncBooleanResultCallback<E = Error> { (err?: E | null, truthValue?: boolean): void; }
21export interface AsyncResultCallback<T, E = Error> { (err?: E | null, result?: T): void; }
22export interface AsyncResultArrayCallback<T, E = Error> { (err?: E | null, results?: Array<T | undefined>): void; }
23export interface AsyncResultObjectCallback<T, E = Error> { (err: E | undefined, results: Dictionary<T | undefined>): void; }
24export interface AsyncResultRestCallback<T, E = Error> { (err?: E | null, ...results: T[]): void; }
25
26export interface AsyncFunction<T, E = Error> { (callback: (err?: E | null, result?: T) => void): void; }
27export interface AsyncFunctionEx<T, E = Error> { (callback: (err?: E | null, ...results: T[]) => void): void; }
28export interface AsyncIterator<T, E = Error> { (item: T, callback: ErrorCallback<E>): void; }
29export interface AsyncForEachOfIterator<T, E = Error> { (item: T, key: number|string, callback: ErrorCallback<E>): void; }
30export interface AsyncResultIterator<T, R, E = Error> { (item: T, callback: AsyncResultCallback<R, E>): void; }
31export interface AsyncResultIteratorPromise<T, R> { (item: T): Promise<R>; }
32export interface AsyncMemoIterator<T, R, E = Error> { (memo: R | undefined, item: T, callback: AsyncResultCallback<R, E>): void; }
33export interface AsyncBooleanIterator<T, E = Error> { (item: T, callback: AsyncBooleanResultCallback<E>): void; }
34
35export interface AsyncWorker<T, E = Error> { (task: T, callback: ErrorCallback<E>): void; }
36export interface AsyncVoidFunction<E = Error> { (callback: ErrorCallback<E>): void; }
37
38export type AsyncAutoTasks<R extends Dictionary<any>, E> = { [K in keyof R]: AsyncAutoTask<R[K], R, E> };
39export type AsyncAutoTask<R1, R extends Dictionary<any>, E> = AsyncAutoTaskFunctionWithoutDependencies<R1, E> | Array<keyof R | AsyncAutoTaskFunction<R1, R, E>>;
40export interface AsyncAutoTaskFunctionWithoutDependencies<R1, E = Error> { (cb: AsyncResultCallback<R1, E> | ErrorCallback<E>): void; }
41export interface AsyncAutoTaskFunction<R1, R extends Dictionary<any>, E = Error> { (results: R, cb: AsyncResultCallback<R1, E> | ErrorCallback<E>): void; }
42
43export interface DataContainer<T> {
44 data: T;
45 priority: number;
46}
47
48export interface CallbackContainer {
49 callback: Function;
50}
51
52export interface PriorityContainer {
53 priority: number;
54}
55
56export interface QueueObject<T> {
57 /**
58 * Returns the number of items waiting to be processed.
59 */
60 length(): number;
61
62 /**
63 * Indicates whether or not any items have been pushed and processed by the queue.
64 */
65 started: boolean;
66
67 /**
68 * Returns the number of items currently being processed.
69 */
70 running(): number;
71
72 /**
73 * Returns an array of items currently being processed.
74 */
75 workersList<TWorker extends DataContainer<T>, CallbackContainer>(): TWorker[];
76
77 /**
78 * Returns false if there are items waiting or being processed, or true if not.
79 */
80 idle(): boolean;
81
82 /**
83 * An integer for determining how many worker functions should be run in parallel.
84 * This property can be changed after a queue is created to alter the concurrency on-the-fly.
85 */
86 concurrency: number;
87
88 /**
89 * An integer that specifies how many items are passed to the worker function at a time.
90 * Only applies if this is a cargo object
91 */
92 payload: number;
93
94 /**
95 * Add a new task to the queue. Calls `callback` once the worker has finished
96 * processing the task.
97 *
98 * Instead of a single task, a tasks array can be submitted.
99 * The respective callback is used for every task in the list.
100 */
101 push<R>(task: T | T[]): Promise<R>;
102 push<R, E = Error>(task: T | T[], callback: AsyncResultCallback<R, E>): void;
103
104 /**
105 * Add a new task to the front of the queue
106 */
107 unshift<R>(task: T | T[]): Promise<R>;
108 unshift<R, E = Error>(task: T | T[], callback: AsyncResultCallback<R, E>): void;
109
110 /**
111 * The same as `q.push`, except this returns a promise that rejects if an error occurs.
112 * The `callback` arg is ignored
113 */
114 pushAsync<R>(task: T | T[]): Promise<R>;
115
116 /**
117 * The same as `q.unshift`, except this returns a promise that rejects if an error occurs.
118 * The `callback` arg is ignored
119 */
120 unshiftAsync<R>(task: T | T[]): Promise<R>;
121
122 /**
123 * Remove items from the queue that match a test function.
124 * The test function will be passed an object with a `data` property,
125 * and a `priority` property, if this is a `priorityQueue` object.
126 */
127 remove(filter: (node: DataContainer<T>) => boolean): void;
128
129 /**
130 * A function that sets a callback that is called when the number of
131 * running workers hits the `concurrency` limit, and further tasks will be
132 * queued.
133 *
134 * If the callback is omitted, `q.saturated()` returns a promise
135 * for the next occurrence.
136 */
137 saturated(): Promise<void>;
138 saturated(handler: () => void): void;
139
140 /**
141 * A function that sets a callback that is called when the number
142 * of running workers is less than the `concurrency` & `buffer` limits,
143 * and further tasks will not be queued
144 *
145 * If the callback is omitted, `q.unsaturated()` returns a promise
146 * for the next occurrence.
147 */
148 unsaturated(): Promise<void>;
149 unsaturated(handler: () => void): void;
150
151 /**
152 * A minimum threshold buffer in order to say that the `queue` is `unsaturated`.
153 */
154 buffer: number;
155
156 /**
157 * A function that sets a callback that is called when the last item from the `queue`
158 * is given to a `worker`.
159 *
160 * If the callback is omitted, `q.empty()` returns a promise for the next occurrence.
161 */
162 empty(): Promise<void>;
163 empty(handler: () => void): void;
164
165 /**
166 * A function that sets a callback that is called when the last item from
167 * the `queue` has returned from the `worker`.
168 *
169 * If the callback is omitted, `q.drain()` returns a promise for the next occurrence.
170 */
171 drain(): Promise<void>;
172 drain(handler: () => void): void;
173
174 /**
175 * A function that sets a callback that is called when a task errors.
176 *
177 * If the callback is omitted, `q.error()` returns a promise that rejects on the next error.
178 */
179 error(): Promise<never>;
180 error(handler: (error: Error, task: T) => void): void;
181
182 /**
183 * A boolean for determining whether the queue is in a paused state.
184 */
185 paused: boolean;
186
187 /**
188 * A function that pauses the processing of tasks until `q.resume()` is called.
189 */
190 pause(): void;
191
192 /**
193 * A function that resumes the processing of queued tasks when the queue
194 * is paused.
195 */
196 resume(): void;
197
198 /**
199 * A function that removes the drain callback and empties remaining tasks
200 * from the queue forcing it to go idle. No more tasks should be pushed to
201 * the queue after calling this function.
202 */
203 kill(): void;
204}
205
206/**
207 * A priorityQueue object to manage the tasks.
208 *
209 * There are two differences between queue and priorityQueue objects:
210 * - `push(task, priority, [callback])` — priority should be a number. If an array of tasks is given, all tasks will be assigned the same priority.
211 * - The `unshift` method was removed.
212 */
213// FIXME: can not use Omit due to ts version restriction. Replace Pick with Omit, when ts 3.5+ will be allowed
214export interface AsyncPriorityQueue<T> extends Pick<QueueObject<T>, Exclude<keyof QueueObject<T>, 'push' | 'unshift'>> {
215 push<R>(task: T | T[], priority?: number): Promise<R>;
216 push<R, E = Error>(task: T | T[], priority: number, callback: AsyncResultCallback<R, E>): void;
217}
218
219/**
220 * @deprecated this is a type that left here for backward compatibility.
221 * Please use QueueObject instead
222 */
223export type AsyncQueue<T> = QueueObject<T>;
224
225/**
226 * @deprecated this is a type that left here for backward compatibility.
227 * Please use QueueObject instead
228 */
229export type AsyncCargoQueue<T = any> = QueueObject<T>;
230
231// Collections
232export function each<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncIterator<T, E>, callback: ErrorCallback<E>): void;
233export function each<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncIterator<T, E>): Promise<void>;
234export const eachSeries: typeof each;
235export function eachLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncIterator<T, E>, callback: ErrorCallback<E>): void;
236export function eachLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncIterator<T, E>): Promise<void>;
237export const forEach: typeof each;
238export const forEachSeries: typeof each;
239export const forEachLimit: typeof eachLimit;
240export function forEachOf<T, E = Error>(obj: IterableCollection<T>, iterator: AsyncForEachOfIterator<T, E>, callback: ErrorCallback<E>): void;
241export function forEachOf<T, E = Error>(obj: IterableCollection<T>, iterator: AsyncForEachOfIterator<T, E>): Promise<void>;
242export const forEachOfSeries: typeof forEachOf;
243export function forEachOfLimit<T, E = Error>(obj: IterableCollection<T>, limit: number, iterator: AsyncForEachOfIterator<T, E>, callback: ErrorCallback<E>): void;
244export function forEachOfLimit<T, E = Error>(obj: IterableCollection<T>, limit: number, iterator: AsyncForEachOfIterator<T, E>): Promise<void>;
245export const eachOf: typeof forEachOf;
246export const eachOfSeries: typeof forEachOf;
247export const eachOfLimit: typeof forEachOfLimit;
248export function map<T, R, E = Error>(
249 arr: IterableCollection<T>,
250 iterator: (AsyncResultIterator<T, R, E> | AsyncResultIteratorPromise<T, R>),
251 callback: AsyncResultArrayCallback<R, E>
252 ): void;
253export function map<T, R, E = Error>(
254 arr: IterableCollection<T>,
255 iterator: (AsyncResultIterator<T, R, E> | AsyncResultIteratorPromise<T, R>)
256 ): Promise<R[]>;
257
258export const mapSeries: typeof map;
259export function mapLimit<T, R, E = Error>(
260 arr: IterableCollection<T>,
261 limit: number, iterator: (AsyncResultIterator<T, R, E> | AsyncResultIteratorPromise<T, R>),
262 callback: AsyncResultArrayCallback<R, E>
263 ): void;
264export function mapLimit<T, R, E = Error>(
265 arr: IterableCollection<T>,
266 limit: number, iterator: (AsyncResultIterator<T, R, E> | AsyncResultIteratorPromise<T, R>)
267 ): Promise<R[]>;
268
269export function mapValuesLimit<T, R, E = Error>(
270 obj: Dictionary<T>,
271 limit: number,
272 iteratee: (value: T, key: string, callback: AsyncResultCallback<R, E>) => void,
273 callback: AsyncResultObjectCallback<R, E>
274 ): void;
275export function mapValuesLimit<T, R, E = Error>(
276 obj: Dictionary<T>,
277 limit: number,
278 iteratee: (value: T, key: string, callback: AsyncResultCallback<R, E>) => void
279): Promise<R>;
280
281export function mapValues<T, R, E = Error>(obj: Dictionary<T>, iteratee: (value: T, key: string, callback: AsyncResultCallback<R, E>) => void, callback: AsyncResultObjectCallback<R, E>): void;
282export function mapValues<T, R, E = Error, C = unknown>(
283 obj: Dictionary<T>,
284 // tslint:disable-next-line:void-return
285 iteratee: (value: T, key: string, callback: C extends undefined ? never : AsyncResultCallback<R, E>) => C extends undefined ? Promise<R> : void
286): Promise<Dictionary<R>>;
287export const mapValuesSeries: typeof mapValues;
288export function filter<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>, callback: AsyncResultArrayCallback<T, E>): void;
289export function filter<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>): Promise<T[]>;
290export const filterSeries: typeof filter;
291export function filterLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncBooleanIterator<T, E>, callback: AsyncResultArrayCallback<T, E>): void;
292export function filterLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncBooleanIterator<T, E>): Promise<T[]>;
293export const select: typeof filter;
294export const selectSeries: typeof filter;
295export const selectLimit: typeof filterLimit;
296export const reject: typeof filter;
297export const rejectSeries: typeof filter;
298export const rejectLimit: typeof filterLimit;
299export function reduce<T, R, E = Error>(arr: T[] | IterableIterator<T>, memo: R, iterator: AsyncMemoIterator<T, R, E>, callback: AsyncResultCallback<R, E>): void;
300export function reduce<T, R, E = Error>(arr: T[] | IterableIterator<T>, memo: R, iterator: AsyncMemoIterator<T, R, E>): Promise<R>;
301export const inject: typeof reduce;
302export const foldl: typeof reduce;
303export const reduceRight: typeof reduce;
304export const foldr: typeof reduce;
305export function detect<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>, callback: AsyncResultCallback<T, E>): void;
306export function detect<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>): Promise<T>;
307export const detectSeries: typeof detect;
308export function detectLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncBooleanIterator<T, E>, callback: AsyncResultCallback<T, E>): void;
309export function detectLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncBooleanIterator<T, E>): Promise<T>;
310export const find: typeof detect;
311export const findSeries: typeof detect;
312export const findLimit: typeof detectLimit;
313export function sortBy<T, V, E = Error>(arr: T[] | IterableIterator<T>, iterator: AsyncResultIterator<T, V, E>, callback: AsyncResultArrayCallback<T, E>): void;
314export function sortBy<T, V, E = Error>(arr: T[] | IterableIterator<T>, iterator: AsyncResultIterator<T, V, E>): Promise<T[]>;
315export function some<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>, callback: AsyncBooleanResultCallback<E>): void;
316export function some<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>): Promise<boolean>;
317export const someSeries: typeof some;
318export function someLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncBooleanIterator<T, E>, callback?: AsyncBooleanResultCallback<E>): void;
319export const any: typeof some;
320export const anySeries: typeof someSeries;
321export const anyLimit: typeof someLimit;
322export function every<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>, callback: AsyncBooleanResultCallback<E>): void;
323export function every<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncBooleanIterator<T, E>): Promise<boolean>;
324export const everySeries: typeof every;
325export function everyLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncBooleanIterator<T, E>, callback: AsyncBooleanResultCallback<E>): void;
326export function everyLimit<T, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncBooleanIterator<T, E>): Promise<boolean>;
327export const all: typeof every;
328export const allSeries: typeof every;
329export const allLimit: typeof everyLimit;
330
331export function concat<T, R, E = Error>(arr: IterableCollection<T>, iterator: AsyncResultIterator<T, R[], E>, callback: AsyncResultArrayCallback<R, E>): void;
332export function concat<T, R, E = Error>(arr: IterableCollection<T>, iterator: AsyncResultIterator<T, R[], E>): Promise<R[]>;
333export function concatLimit<T, R, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncResultIterator<T, R[], E>, callback: AsyncResultArrayCallback<R, E>): void;
334export function concatLimit<T, R, E = Error>(arr: IterableCollection<T>, limit: number, iterator: AsyncResultIterator<T, R[], E>): Promise<R[]>;
335export const concatSeries: typeof concat;
336export const flatMap: typeof concat;
337export const flatMapLimit: typeof concatLimit;
338export const flatMapSeries: typeof concatSeries;
339
340export function groupBy<T, K, E = Error>(iterable: IterableCollection<T>, iterator: AsyncResultIterator<T, K, E>, callback: AsyncResultCallback<Record<string, T[]>, E>): void;
341export function groupBy<T, K, E = Error>(iterable: IterableCollection<T>, iterator: AsyncResultIterator<T, K, E>): Promise<Record<string, T[]>>;
342export function groupByLimit<T, K, E = Error>(iterable: IterableCollection<T>, limit: number, iterator: AsyncResultIterator<T, K, E>, callback: AsyncResultCallback<Record<string, T[]>, E>): void;
343export function groupByLimit<T, K, E = Error>(iterable: IterableCollection<T>, limit: number, iterator: AsyncResultIterator<T, K, E>): Promise<Record<string, T[]>>;
344export const groupBySeries: typeof groupBy;
345
346// Control Flow
347export function series<T, E = Error>(tasks: Array<AsyncFunction<T, E>>, callback: AsyncResultArrayCallback<T, E>): void;
348export function series<T, E = Error>(tasks: Dictionary<AsyncFunction<T, E>>, callback: AsyncResultObjectCallback<T, E>): void;
349export function series<T, E = Error>(tasks: Array<AsyncFunction<T, E>>): Promise<T[]>;
350export function series<T, E = Error>(tasks: Dictionary<AsyncFunction<T, E>>): Promise<Dictionary<T>>;
351export function parallel<T, E = Error>(tasks: Array<AsyncFunction<T, E>>, callback: AsyncResultArrayCallback<T, E>): void;
352export function parallel<T, E = Error>(tasks: Dictionary<AsyncFunction<T, E>>, callback: AsyncResultObjectCallback<T, E>): void;
353export function parallel<T, R, E = Error>(tasks: Array<AsyncFunction<T, E>> | Dictionary<AsyncFunction<T, E>>): Promise<R>;
354export function parallelLimit<T, E = Error>(tasks: Array<AsyncFunction<T, E>>, limit: number, callback: AsyncResultArrayCallback<T, E>): void;
355export function parallelLimit<T, E = Error>(tasks: Dictionary<AsyncFunction<T, E>>, limit: number, callback: AsyncResultObjectCallback<T, E>): void;
356export function parallelLimit<T, R, E = Error>(tasks: Array<AsyncFunction<T, E>> | Dictionary<AsyncFunction<T, E>>, limit: number): Promise<R>;
357
358export function whilst<T, E = Error>(
359 test: (cb: AsyncBooleanResultCallback) => void,
360 fn: AsyncFunctionEx<T, E>,
361 callback: AsyncResultRestCallback<T, E>
362): void;
363export function whilst<T, R, E = Error>(
364 test: (cb: AsyncBooleanResultCallback) => void,
365 fn: AsyncFunctionEx<T, E>
366): Promise<R>;
367export function doWhilst<T, E = Error>(
368 fn: AsyncFunctionEx<T, E>,
369 test: (/* ...results: T[], */ cb: AsyncBooleanResultCallback) => void,
370 callback: AsyncResultRestCallback<T, E>
371): void;
372export function doWhilst<T, R, E = Error>(
373 fn: AsyncFunctionEx<T, E>,
374 test: (/* ...results: T[], */ cb: AsyncBooleanResultCallback) => void
375): Promise<R>;
376export function until<T, E = Error>(
377 test: (cb: AsyncBooleanResultCallback) => void,
378 fn: AsyncFunctionEx<T, E>,
379 callback: AsyncResultRestCallback<T, E>
380): void;
381export function until<T, R, E = Error>(
382 test: (cb: AsyncBooleanResultCallback) => void,
383 fn: AsyncFunctionEx<T, E>
384): Promise<R>;
385export function doUntil<T, E = Error>(
386 fn: AsyncFunctionEx<T, E>,
387 test: (/* ...results: T[], */ cb: AsyncBooleanResultCallback) => void,
388 callback: AsyncResultRestCallback<T, E>
389): void;
390export function doUntil<T, R, E = Error>(
391 fn: AsyncFunctionEx<T, E>,
392 test: (/* ...results: T[], */ cb: AsyncBooleanResultCallback) => void
393): Promise<R>;
394
395export function during<E = Error>(test: (testCallback: AsyncBooleanResultCallback<E>) => void, fn: AsyncVoidFunction<E>, callback: ErrorCallback<E>): void;
396export function doDuring<E = Error>(fn: AsyncVoidFunction<E>, test: (testCallback: AsyncBooleanResultCallback<E>) => void, callback: ErrorCallback<E>): void;
397export function forever<E = Error>(next: (next: ErrorCallback<E>) => void, errBack: ErrorCallback<E>): void;
398export function waterfall<T>(tasks: Function[]): Promise<T>;
399export function waterfall<T, E = Error>(tasks: Function[], callback: AsyncResultCallback<T, E>): void;
400export function compose(...fns: Function[]): Function;
401export function seq(...fns: Function[]): Function;
402export function applyEach(fns: Function[], ...argsAndCallback: any[]): void; // applyEach(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional.
403export function applyEachSeries(fns: Function[], ...argsAndCallback: any[]): void; // applyEachSeries(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional.
404export function queue<T, E = Error>(worker: AsyncWorker<T, E>, concurrency?: number): QueueObject<T>;
405export function queue<T, R, E = Error>(worker: AsyncResultIterator<T, R, E>, concurrency?: number): QueueObject<T>;
406export function priorityQueue<T, E = Error>(worker: AsyncWorker<T, E>, concurrency?: number): AsyncPriorityQueue<T>;
407export function cargo<T, E = Error>(worker: AsyncWorker<T[], E>, payload?: number): QueueObject<T>;
408export function cargoQueue<T, E = Error>(
409 worker: AsyncWorker<T[], E>,
410 concurrency?: number,
411 payload?: number,
412): QueueObject<T>;
413export function auto<R extends Dictionary<any>, E = Error>(tasks: AsyncAutoTasks<R, E>, concurrency?: number): Promise<R>;
414export function auto<R extends Dictionary<any>, E = Error>(tasks: AsyncAutoTasks<R, E>, concurrency: number, callback: AsyncResultCallback<R, E>): void;
415export function auto<R extends Dictionary<any>, E = Error>(tasks: AsyncAutoTasks<R, E>, callback: AsyncResultCallback<R, E>): void;
416export function autoInject<E = Error>(tasks: any, callback?: AsyncResultCallback<any, E>): void;
417
418export interface RetryOptions<E> {
419 times?: number | undefined;
420 interval?: number | ((retryCount: number) => number) | undefined;
421 errorFilter?: ((error: E) => boolean) | undefined;
422}
423export function retry<T, E = Error>(
424 task: (() => Promise<T>) | ((callback: AsyncResultCallback<T, E>) => void),
425): Promise<T>;
426export function retry<T, E = Error>(
427 opts: number | RetryOptions<E>,
428 task: (() => Promise<T>) | ((callback: AsyncResultCallback<T, E>) => void),
429): Promise<T>;
430export function retry<T, E = Error>(
431 task: (() => Promise<T>) | ((callback: AsyncResultCallback<T, E>) => void),
432 callback: AsyncResultCallback<T, E>,
433): void;
434export function retry<T, E = Error>(
435 opts: number | RetryOptions<E>,
436 task: (() => Promise<T>) | ((callback: AsyncResultCallback<T, E>) => void),
437 callback: AsyncResultCallback<T, E>,
438): void;
439
440export function retryable<T, E = Error>(task: AsyncFunction<T, E>): AsyncFunction<T, E>;
441export function retryable<T, E = Error>(
442 opts: number | (RetryOptions<E> & { arity?: number | undefined }),
443 task: AsyncFunction<T, E>,
444): AsyncFunction<T, E>;
445export function apply<E = Error>(fn: Function, ...args: any[]): AsyncFunction<any, E>;
446export function nextTick(callback: Function, ...args: any[]): void;
447export const setImmediate: typeof nextTick;
448
449export function reflect<T, E = Error>(fn: AsyncFunction<T, E>): (callback: (err: null, result: {error?: E | undefined, value?: T | undefined}) => void) => void;
450export function reflectAll<T, E = Error>(tasks: Array<AsyncFunction<T, E>>): Array<(callback: (err: null, result: {error?: E | undefined, value?: T | undefined}) => void) => void>;
451
452export function timeout<T, E = Error>(fn: AsyncFunction<T, E>, milliseconds: number, info?: any): AsyncFunction<T, E>;
453export function timeout<T, R, E = Error>(fn: AsyncResultIterator<T, R, E>, milliseconds: number, info?: any): AsyncResultIterator<T, R, E>;
454
455export function times<T, E = Error>(n: number, iterator: (AsyncResultIterator<number, T, E> | AsyncResultIteratorPromise<number, T>), callback: AsyncResultArrayCallback<T, E>): void;
456export function times<T, E = Error>(n: number, iterator: (AsyncResultIterator<number, T, E> | AsyncResultIteratorPromise<number, T>)): Promise<T>;
457
458export const timesSeries: typeof times;
459export function timesLimit<T, E = Error>(
460 n: number,
461 limit: number,
462 iterator: (AsyncResultIterator<number, T, E> | AsyncResultIteratorPromise<number, T>),
463 callback: AsyncResultArrayCallback<T, E>
464 ): void;
465export function timesLimit<T, E = Error>(
466 n: number,
467 limit: number,
468 iterator: (AsyncResultIterator<number, T, E> | AsyncResultIteratorPromise<number, T>)
469 ): Promise<T>;
470
471export function transform<T, R, E = Error>(arr: T[], iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void, callback?: AsyncResultArrayCallback<T, E>): void;
472export function transform<T, R, E = Error>(arr: T[], acc: R[], iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void, callback?: AsyncResultArrayCallback<T, E>): void;
473
474export function transform<T, R, E = Error>(
475 arr: {[key: string]: T},
476 iteratee: (acc: {[key: string]: R}, item: T, key: string, callback: (error?: E) => void) => void,
477 callback?: AsyncResultObjectCallback<T, E>
478 ): void;
479
480export function transform<T, R, E = Error>(
481 arr: {[key: string]: T},
482 acc: {[key: string]: R},
483 iteratee: (acc: {[key: string]: R}, item: T, key: string, callback: (error?: E) => void) => void,
484 callback?: AsyncResultObjectCallback<T, E>
485 ): void;
486
487export function race<T, E = Error>(tasks: Array<AsyncFunction<T, E>>, callback: AsyncResultCallback<T, E>): void;
488
489export function tryEach<T, E = Error>(tasks: IterableCollection<AsyncFunction<T>>, callback: AsyncResultCallback<T, E>): void;
490export function tryEach<T>(tasks: IterableCollection<AsyncFunction<T>>): Promise<T>;
491
492// Utils
493export function memoize(fn: Function, hasher?: Function): Function;
494export function unmemoize(fn: Function): Function;
495export function ensureAsync(fn: (... argsAndCallback: any[]) => void): Function;
496export function constant(...values: any[]): AsyncFunction<any>;
497export function asyncify(fn: Function): (...args: any[]) => any;
498export function wrapSync(fn: Function): Function;
499export function log(fn: Function, ...args: any[]): void;
500export function dir(fn: Function, ...args: any[]): void;