diff --git a/types/async/index.d.ts b/types/async/index.d.ts index 54585ddc28..8d7031bff1 100644 --- a/types/async/index.d.ts +++ b/types/async/index.d.ts @@ -106,7 +106,12 @@ export interface AsyncCargo { push(task: any, callback?: Function): void; saturated(): void; empty(): void; - drain(): void; + /** + * a function that sets a callback that is called when the last item from the queue has returned from the worker. + * If the callback is omitted, q.drain() returns a promise for the next occurrence. + */ + drain(): Promise; + drain(handler: () => void): void; idle(): boolean; pause(): void; resume(): void; diff --git a/types/async/test/index.ts b/types/async/test/index.ts index 7516e49192..7e3cd35872 100644 --- a/types/async/test/index.ts +++ b/types/async/test/index.ts @@ -256,6 +256,8 @@ const cargo = async.cargo((tasks, callback) => { } callback(); }, 2); +cargo.drain(); // $ExpectType Promise +cargo.drain(() => { console.log('done processing queue'); }); // $ExpectType void // add some items cargo.push({ name: 'foo' }, (err: Error) => { console.log('finished processing foo'); });