// Type definitions for Async 1.4.2
// Project: https://github.com/caolan/async
// Definitions by: Boris Yankov , Arseniy Maximov , Joe Herman
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Dictionary { [key: string]: T; }
interface ErrorCallback { (err?: Error): void; }
interface AsyncResultCallback { (err: Error, result: T): void; }
interface AsyncResultArrayCallback { (err: Error, results: T[]): void; }
interface AsyncResultObjectCallback { (err: Error, results: Dictionary): void; }
interface AsyncFunction { (callback: (err?: Error, result?: T) => void): void; }
interface AsyncIterator { (item: T, callback: ErrorCallback): void; }
interface AsyncForEachOfIterator { (item: T, key: number|string, callback: ErrorCallback): void; }
interface AsyncResultIterator { (item: T, callback: AsyncResultCallback): void; }
interface AsyncMemoIterator { (memo: R, item: T, callback: AsyncResultCallback): void; }
interface AsyncBooleanIterator { (item: T, callback: (err: string, truthValue: boolean) => void): void; }
interface AsyncWorker { (task: T, callback: ErrorCallback): void; }
interface AsyncVoidFunction { (callback: ErrorCallback): void; }
interface AsyncQueue {
length(): number;
started: boolean;
running(): number;
idle(): boolean;
concurrency: number;
push(task: T, callback?: ErrorCallback): void;
push(task: T[], callback?: ErrorCallback): void;
unshift(task: T, callback?: ErrorCallback): void;
unshift(task: T[], callback?: ErrorCallback): void;
saturated: () => any;
empty: () => any;
drain: () => any;
paused: boolean;
pause(): void
resume(): void;
kill(): void;
}
interface AsyncPriorityQueue {
length(): number;
concurrency: number;
started: boolean;
paused: boolean;
push(task: T, priority: number, callback?: AsyncResultArrayCallback): void;
push(task: T[], priority: number, callback?: AsyncResultArrayCallback): void;
saturated: () => any;
empty: () => any;
drain: () => any;
running(): number;
idle(): boolean;
pause(): void;
resume(): void;
kill(): void;
}
interface AsyncCargo {
length(): number;
payload: number;
push(task: any, callback? : Function): void;
push(task: any[], callback? : Function): void;
saturated(): void;
empty(): void;
drain(): void;
idle(): boolean;
pause(): void;
resume(): void;
kill(): void;
}
interface Async {
// Collections
each(arr: T[], iterator: AsyncIterator, callback?: ErrorCallback): void;
eachSeries(arr: T[], iterator: AsyncIterator, callback?: ErrorCallback): void;
eachLimit(arr: T[], limit: number, iterator: AsyncIterator, callback?: ErrorCallback): void;
forEachOf(obj: any, iterator: (item: any, key: string|number, callback?: ErrorCallback) => void, callback: ErrorCallback): void;
forEachOf(obj: T[], iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void;
forEachOfSeries(obj: any, iterator: (item: any, key: string|number, callback?: ErrorCallback) => void, callback: ErrorCallback): void;
forEachOfSeries(obj: T[], iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void;
forEachOfLimit(obj: any, limit: number, iterator: (item: any, key: string|number, callback?: ErrorCallback) => void, callback: ErrorCallback): void;
forEachOfLimit(obj: T[], limit: number, iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void;
map(arr: T[], iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): any;
mapSeries(arr: T[], iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): any;
mapLimit(arr: T[], limit: number, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): any;
filter(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
select(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
filterSeries(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
selectSeries(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
filterLimit(arr: T[], limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
selectLimit(arr: T[], limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
reject(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
rejectSeries(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
rejectLimit(arr: T[], limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): any;
reduce(arr: T[], memo: R, iterator: AsyncMemoIterator, callback?: AsyncResultCallback): any;
inject(arr: T[], memo: R, iterator: AsyncMemoIterator, callback?: AsyncResultCallback): any;
foldl(arr: T[], memo: R, iterator: AsyncMemoIterator, callback?: AsyncResultCallback): any;
reduceRight(arr: T[], memo: R, iterator: AsyncMemoIterator, callback: AsyncResultCallback): any;
foldr(arr: T[], memo: R, iterator: AsyncMemoIterator, callback: AsyncResultCallback): any;
detect(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): any;
detectSeries(arr: T[], iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): any;
detectLimit(arr: T[], limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): any;
sortBy(arr: T[], iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): any;
some(arr: T[], iterator: AsyncBooleanIterator, callback?: (result: boolean) => void): any;
someLimit(arr: T[], limit: number, iterator: AsyncBooleanIterator, callback?: (result: boolean) => void): any;
any(arr: T[], iterator: AsyncBooleanIterator, callback?: (result: boolean) => void): any;
every(arr: T[], iterator: AsyncBooleanIterator, callback?: (result: boolean) => any): any;
everyLimit(arr: T[], limit: number, iterator: AsyncBooleanIterator, callback?: (result: boolean) => any): any;
all(arr: T[], iterator: AsyncBooleanIterator, callback?: (result: boolean) => any): any;
concat(arr: T[], iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): any;
concatSeries(arr: T[], iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): any;
// Control Flow
series(tasks: AsyncFunction[], callback?: AsyncResultArrayCallback): void;
series(tasks: Dictionary>, callback?: AsyncResultObjectCallback): void;
parallel(tasks: Array>, callback?: AsyncResultArrayCallback): void;
parallel(tasks: Dictionary>, callback?: AsyncResultObjectCallback): void;
parallelLimit(tasks: Array>, limit: number, callback?: AsyncResultArrayCallback): void;
parallelLimit(tasks: Dictionary>, limit: number, callback?: AsyncResultObjectCallback): void;
whilst(test: () => boolean, fn: AsyncVoidFunction, callback: (err: any) => void): void;
doWhilst(fn: AsyncVoidFunction, test: () => boolean, callback: (err: any) => void): void;
until(test: () => boolean, fn: AsyncVoidFunction, callback: (err: any) => void): void;
doUntil(fn: AsyncVoidFunction, test: () => boolean, callback: (err: any) => void): void;
during(test: (testCallback : (error: Error, truth: boolean) => void) => void, fn: AsyncVoidFunction, callback: (err: any) => void): void;
doDuring(fn: AsyncVoidFunction, test: (testCallback: (error: Error, truth: boolean) => void) => void, callback: (err: any) => void): void;
forever(next: (errCallback : (err: Error) => void) => void, errBack: (err: Error) => void) : void;
waterfall(tasks: Function[], callback?: (err: Error, results?: any) => void): void;
compose(...fns: Function[]): Function;
seq(...fns: Function[]): Function;
applyEach(fns: Function[], argsAndCallback: any[]): void; // applyEach(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional.
applyEachSeries(fns: Function[], argsAndCallback: any[]): void; // applyEachSeries(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional.
queue(worker: AsyncWorker, concurrency?: number): AsyncQueue;
priorityQueue(worker: AsyncWorker, concurrency: number): AsyncPriorityQueue;
cargo(worker : (tasks: any[], callback : ErrorCallback) => void, payload? : number) : AsyncCargo;
auto(tasks: any, callback?: (error: Error, results: any) => void): void;
retry(opts: number, task: (callback : AsyncResultCallback, results: any) => void, callback: (error: Error, results: any) => void): void;
retry(opts: { times: number, interval: number|((retryCount: number) => number) }, task: (callback: AsyncResultCallback, results : any) => void, callback: (error: Error, results: any) => void): void;
iterator(tasks: Function[]): Function;
apply(fn: Function, ...arguments: any[]): AsyncFunction;
nextTick(callback: Function): void;
setImmediate(callback: Function): void;
times (n: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): void;
timesSeries(n: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): void;
timesLimit(n: number, limit: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): void;
// Utils
memoize(fn: Function, hasher?: Function): Function;
unmemoize(fn: Function): Function;
ensureAsync(fn: (... argsAndCallback: any[]) => void): Function;
constant(...values: any[]): Function;
asyncify(fn: Function): Function;
wrapSync(fn: Function): Function;
log(fn: Function, ...arguments: any[]): void;
dir(fn: Function, ...arguments: any[]): void;
noConflict(): Async;
}
declare var async: Async;
declare module "async" {
export = async;
}