UNPKG

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