@types/after-all-results
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

Installation

npm install --save @types/after-all-results

Summary

This package contains type definitions for after-all-results (https://github.com/watson/after-all-results).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/after-all-results.

index.d.ts

export = afterAllResults;

/**
 * Runs multiple async functions in parallel and collects all their results in an array.
 *
 * **Note:** It is important that all `next()` calls are done on the same
 * tick as the initial call to `afterAll()`!
 *
 * @example
 * import afterAll = require('after-all-results');
 *
 * const next = afterAll((err, results: [string, number]) => {
 *   // all done!
 *   console.log(results);
 * });
 *
 * someAsyncFunctionProducingString(next());
 * anotherAsyncFunctionProducingNumber(next());
 *
 * @example
 * import afterAll = require('after-all-results');
 *
 * const next = afterAll((err, results: [string, boolean]) => {
 *   // results will be an array of `arg1` from below
 *   console.log('Done with everything!');
 * });
 *
 * // some exemplary async functions
 * declare function async1(cb: (err: Error | null, arg1: string, arg2: number) => void): void;
 * declare function async2(cb: (err: Error | null, arg1: boolean, arg2: string) => void): void;
 *
 * async1(
 *   next((err, ...args) => {
 *     const [arg1, arg2] = args as [string, number];
 *     console.log('Done with first call to async');
 *   }),
 * );
 *
 * async2(
 *   next((err, ...args) => {
 *     const [arg1, arg2] = args as [boolean, string];
 *     console.log('Done with second call to async');
 *   }),
 * );
 */
declare function afterAllResults<TResults extends any[]>(
    done: (err: Error | null, results: TResults) => void,
): (
    callback?: (err: Error | null, ...args: unknown[]) => void,
) => (err: Error | null, result: ArrayElementType<TResults>) => void;

type ArrayElementType<TArr extends unknown[]> = TArr extends ReadonlyArray<infer T> ? T : never;

Additional Details

  • Last updated: Mon, 06 Nov 2023 22:41:04 GMT
  • Dependencies: none

Credits

These definitions were written by BendingBender.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/after-all-results

Weekly Downloads

55

Version

2.0.2

License

MIT

Unpacked Size

5.98 kB

Total Files

5

Last publish

Collaborators

  • types