import CancelablePromise from './CancelablePromise.js'; import './Promise.js'; /** * Represents the error value in promises returned by the `join` * function if at least one promise fails with an error. */ interface JoinError { /** The first error */ error: any; /** The results in the same order as the input promises. */ all: any[]; /** All errors. */ errors: Record; } /** * Wait to finish of all given promises. * This method does not fail fast like Promise.all, it will wait until all promises are executed. * * Note that the standard [Promise.allSettled](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) * function may be a superior alternative. * * @param promises the promises to wait for. * @returns to wait for all promises to finish. * @example * ```ts * import join from "apprt-core/join"; * const a = fetch("test.json"); * const b = fetch("test2.json"); * * try { * const results = await join([a, b]); * const ajson = results[0]; * const bjson = results[1]; * } catch (e) { * const joinError: JoinError = e; * // joinError.all => results, e.g. e.all[0] === result of ajson * // joinError.error => first of all errors * // joinError.errors => all errors * } * ``` */ declare function join(promises: (T | PromiseLike)[]): CancelablePromise; export { join as default, join }; export type { JoinError };