|
| 1 | +// Type definitions for Async 1.4.2 |
| 2 | +// Project: https://github.com/caolan/async |
| 3 | +// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Arseniy Maximov <https://github.com/kern0>, Joe Herman <https://github.com/Penryn> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +interface Dictionary<T> { [key: string]: T; } |
| 7 | + |
| 8 | +interface ErrorCallback { (err?: Error): void; } |
| 9 | +interface AsyncResultCallback<T> { (err: Error, result: T): void; } |
| 10 | +interface AsyncResultArrayCallback<T> { (err: Error, results: T[]): void; } |
| 11 | +interface AsyncResultObjectCallback<T> { (err: Error, results: Dictionary<T>): void; } |
| 12 | + |
| 13 | +interface AsyncFunction<T> { (callback: (err?: Error, result?: T) => void): void; } |
| 14 | +interface AsyncIterator<T> { (item: T, callback: ErrorCallback): void; } |
| 15 | +interface AsyncForEachOfIterator<T> { (item: T, key: number, callback: ErrorCallback): void; } |
| 16 | +interface AsyncResultIterator<T, R> { (item: T, callback: AsyncResultCallback<R>): void; } |
| 17 | +interface AsyncMemoIterator<T, R> { (memo: R, item: T, callback: AsyncResultCallback<R>): void; } |
| 18 | +interface AsyncBooleanIterator<T> { (item: T, callback: (err: string, truthValue: boolean) => void): void; } |
| 19 | + |
| 20 | +interface AsyncWorker<T> { (task: T, callback: ErrorCallback): void; } |
| 21 | +interface AsyncVoidFunction { (callback: ErrorCallback): void; } |
| 22 | + |
| 23 | +interface AsyncQueue<T> { |
| 24 | + length(): number; |
| 25 | + started: boolean; |
| 26 | + running(): number; |
| 27 | + idle(): boolean; |
| 28 | + concurrency: number; |
| 29 | + push(task: T, callback?: ErrorCallback): void; |
| 30 | + push(task: T[], callback?: ErrorCallback): void; |
| 31 | + unshift(task: T, callback?: ErrorCallback): void; |
| 32 | + unshift(task: T[], callback?: ErrorCallback): void; |
| 33 | + saturated: () => any; |
| 34 | + empty: () => any; |
| 35 | + drain: () => any; |
| 36 | + paused: boolean; |
| 37 | + pause(): void |
| 38 | + resume(): void; |
| 39 | + kill(): void; |
| 40 | +} |
| 41 | + |
| 42 | +interface AsyncPriorityQueue<T> { |
| 43 | + length(): number; |
| 44 | + concurrency: number; |
| 45 | + started: boolean; |
| 46 | + paused: boolean; |
| 47 | + push(task: T, priority: number, callback?: AsyncResultArrayCallback<T>): void; |
| 48 | + push(task: T[], priority: number, callback?: AsyncResultArrayCallback<T>): void; |
| 49 | + saturated: () => any; |
| 50 | + empty: () => any; |
| 51 | + drain: () => any; |
| 52 | + running(): number; |
| 53 | + idle(): boolean; |
| 54 | + pause(): void; |
| 55 | + resume(): void; |
| 56 | + kill(): void; |
| 57 | +} |
| 58 | + |
| 59 | +interface AsyncCargo { |
| 60 | + length(): number; |
| 61 | + payload: number; |
| 62 | + push(task: any, callback? : Function): void; |
| 63 | + push(task: any[], callback? : Function): void; |
| 64 | + saturated(): void; |
| 65 | + empty(): void; |
| 66 | + drain(): void; |
| 67 | + idle(): boolean; |
| 68 | + pause(): void; |
| 69 | + resume(): void; |
| 70 | + kill(): void; |
| 71 | +} |
| 72 | + |
| 73 | +interface Async { |
| 74 | + |
| 75 | + // Collections |
| 76 | + each<T>(arr: T[], iterator: AsyncIterator<T>, callback?: ErrorCallback): void; |
| 77 | + eachSeries<T>(arr: T[], iterator: AsyncIterator<T>, callback?: ErrorCallback): void; |
| 78 | + eachLimit<T>(arr: T[], limit: number, iterator: AsyncIterator<T>, callback?: ErrorCallback): void; |
| 79 | + forEachOf(obj: any, iterator: (item: any, key: string|number, callback?: ErrorCallback) => void, callback: ErrorCallback): void; |
| 80 | + forEachOf<T>(obj: T[], iterator: AsyncForEachOfIterator<T>, callback?: ErrorCallback): void; |
| 81 | + forEachOfSeries(obj: any, iterator: (item: any, key: string|number, callback?: ErrorCallback) => void, callback: ErrorCallback): void; |
| 82 | + forEachOfSeries<T>(obj: T[], iterator: AsyncForEachOfIterator<T>, callback?: ErrorCallback): void; |
| 83 | + forEachOfLimit(obj: any, limit: number, iterator: (item: any, key: string|number, callback?: ErrorCallback) => void, callback: ErrorCallback): void; |
| 84 | + forEachOfLimit<T>(obj: T[], limit: number, iterator: AsyncForEachOfIterator<T>, callback?: ErrorCallback): void; |
| 85 | + map<T, R>(arr: T[], iterator: AsyncResultIterator<T, R>, callback?: AsyncResultArrayCallback<R>): any; |
| 86 | + mapSeries<T, R>(arr: T[], iterator: AsyncResultIterator<T, R>, callback?: AsyncResultArrayCallback<R>): any; |
| 87 | + mapLimit<T, R>(arr: T[], limit: number, iterator: AsyncResultIterator<T, R>, callback?: AsyncResultArrayCallback<R>): any; |
| 88 | + filter<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 89 | + select<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 90 | + filterSeries<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 91 | + selectSeries<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 92 | + filterLimit<T>(arr: T[], limit: number, iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 93 | + selectLimit<T>(arr: T[], limit: number, iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 94 | + reject<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 95 | + rejectSeries<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 96 | + rejectLimit<T>(arr: T[], limit: number, iterator: AsyncBooleanIterator<T>, callback?: AsyncResultArrayCallback<T>): any; |
| 97 | + reduce<T, R>(arr: T[], memo: R, iterator: AsyncMemoIterator<T, R>, callback?: AsyncResultCallback<R>): any; |
| 98 | + inject<T, R>(arr: T[], memo: R, iterator: AsyncMemoIterator<T, R>, callback?: AsyncResultCallback<R>): any; |
| 99 | + foldl<T, R>(arr: T[], memo: R, iterator: AsyncMemoIterator<T, R>, callback?: AsyncResultCallback<R>): any; |
| 100 | + reduceRight<T, R>(arr: T[], memo: R, iterator: AsyncMemoIterator<T, R>, callback: AsyncResultCallback<R>): any; |
| 101 | + foldr<T, R>(arr: T[], memo: R, iterator: AsyncMemoIterator<T, R>, callback: AsyncResultCallback<R>): any; |
| 102 | + detect<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultCallback<T>): any; |
| 103 | + detectSeries<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: AsyncResultCallback<T>): any; |
| 104 | + detectLimit<T>(arr: T[], limit: number, iterator: AsyncBooleanIterator<T>, callback?: AsyncResultCallback<T>): any; |
| 105 | + sortBy<T, V>(arr: T[], iterator: AsyncResultIterator<T, V>, callback?: AsyncResultArrayCallback<T>): any; |
| 106 | + some<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: (result: boolean) => void): any; |
| 107 | + someLimit<T>(arr: T[], limit: number, iterator: AsyncBooleanIterator<T>, callback?: (result: boolean) => void): any; |
| 108 | + any<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: (result: boolean) => void): any; |
| 109 | + every<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: (result: boolean) => any): any; |
| 110 | + everyLimit<T>(arr: T[], limit: number, iterator: AsyncBooleanIterator<T>, callback?: (result: boolean) => any): any; |
| 111 | + all<T>(arr: T[], iterator: AsyncBooleanIterator<T>, callback?: (result: boolean) => any): any; |
| 112 | + concat<T, R>(arr: T[], iterator: AsyncResultIterator<T, R[]>, callback?: AsyncResultArrayCallback<R>): any; |
| 113 | + concatSeries<T, R>(arr: T[], iterator: AsyncResultIterator<T, R[]>, callback?: AsyncResultArrayCallback<R>): any; |
| 114 | + |
| 115 | + // Control Flow |
| 116 | + series<T>(tasks: AsyncFunction<T>[], callback?: AsyncResultArrayCallback<T>): void; |
| 117 | + series<T>(tasks: Dictionary<AsyncFunction<T>>, callback?: AsyncResultObjectCallback<T>): void; |
| 118 | + parallel<T>(tasks: Array<AsyncFunction<T>>, callback?: AsyncResultArrayCallback<T>): void; |
| 119 | + parallel<T>(tasks: Dictionary<AsyncFunction<T>>, callback?: AsyncResultObjectCallback<T>): void; |
| 120 | + parallelLimit<T>(tasks: Array<AsyncFunction<T>>, limit: number, callback?: AsyncResultArrayCallback<T>): void; |
| 121 | + parallelLimit<T>(tasks: Dictionary<AsyncFunction<T>>, limit: number, callback?: AsyncResultObjectCallback<T>): void; |
| 122 | + whilst(test: () => boolean, fn: AsyncVoidFunction, callback: (err: any) => void): void; |
| 123 | + doWhilst(fn: AsyncVoidFunction, test: () => boolean, callback: (err: any) => void): void; |
| 124 | + until(test: () => boolean, fn: AsyncVoidFunction, callback: (err: any) => void): void; |
| 125 | + doUntil(fn: AsyncVoidFunction, test: () => boolean, callback: (err: any) => void): void; |
| 126 | + during(test: (testCallback : (error: Error, truth: boolean) => void) => void, fn: AsyncVoidFunction, callback: (err: any) => void): void; |
| 127 | + doDuring(fn: AsyncVoidFunction, test: (testCallback: (error: Error, truth: boolean) => void) => void, callback: (err: any) => void): void; |
| 128 | + forever(next: (errCallback : (err: Error) => void) => void, errBack: (err: Error) => void) : void; |
| 129 | + waterfall(tasks: Function[], callback?: (err: Error, results?: any) => void): void; |
| 130 | + compose(...fns: Function[]): Function; |
| 131 | + seq(...fns: Function[]): Function; |
| 132 | + applyEach(fns: Function[], argsAndCallback: any[]): void; // applyEach(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional. |
| 133 | + applyEachSeries(fns: Function[], argsAndCallback: any[]): void; // applyEachSeries(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional. |
| 134 | + queue<T>(worker: AsyncWorker<T>, concurrency?: number): AsyncQueue<T>; |
| 135 | + priorityQueue<T>(worker: AsyncWorker<T>, concurrency: number): AsyncPriorityQueue<T>; |
| 136 | + cargo(worker : (tasks: any[], callback : ErrorCallback) => void, payload? : number) : AsyncCargo; |
| 137 | + auto(tasks: any, callback?: (error: Error, results: any) => void): void; |
| 138 | + retry<T>(opts: number, task: (callback : AsyncResultCallback<T>, results: any) => void, callback: (error: Error, results: any) => void): void; |
| 139 | + retry<T>(opts: { times: number, interval: number }, task: (callback: AsyncResultCallback<T>, results : any) => void, callback: (error: Error, results: any) => void): void; |
| 140 | + iterator(tasks: Function[]): Function; |
| 141 | + apply(fn: Function, ...arguments: any[]): AsyncFunction<any>; |
| 142 | + nextTick(callback: Function): void; |
| 143 | + setImmediate(callback: Function): void; |
| 144 | + |
| 145 | + times<T> (n: number, iterator: AsyncResultIterator<number, T>, callback: AsyncResultArrayCallback<T>): void; |
| 146 | + timesSeries<T>(n: number, iterator: AsyncResultIterator<number, T>, callback: AsyncResultArrayCallback<T>): void; |
| 147 | + timesLimit<T>(n: number, limit: number, iterator: AsyncResultIterator<number, T>, callback: AsyncResultArrayCallback<T>): void; |
| 148 | + |
| 149 | + // Utils |
| 150 | + memoize(fn: Function, hasher?: Function): Function; |
| 151 | + unmemoize(fn: Function): Function; |
| 152 | + ensureAsync(fn: (... argsAndCallback: any[]) => void): Function; |
| 153 | + constant(...values: any[]): Function; |
| 154 | + asyncify(fn: Function): Function; |
| 155 | + wrapSync(fn: Function): Function; |
| 156 | + log(fn: Function, ...arguments: any[]): void; |
| 157 | + dir(fn: Function, ...arguments: any[]): void; |
| 158 | + noConflict(): Async; |
| 159 | +} |
| 160 | + |
| 161 | +declare var async: Async; |
| 162 | + |
| 163 | +declare module "async" { |
| 164 | + export = async; |
| 165 | +} |
0 commit comments