import { Result, ResultValidErrors } from "t-result"; //#region src/concurrentCalls.d.ts declare class ConcurrentCallsAggregateError extends AggregateError { errors: ResultValidErrors[]; total: number; failed: number; constructor(errors: ResultValidErrors[], total: number, failed: number); } declare class ConcurrentCallsWithMetadataAggregateError extends AggregateError { errors: ResultValidErrors[]; errorsWithMetadata: { error: ResultValidErrors; metadata: M; }[]; total: number; failed: number; constructor(errors: { error: ResultValidErrors; metadata: M; }[], total: number, failed: number); } type ValidMetadata = string | number | boolean | Record; type RunProps = { delayStart?: (index: number) => number; }; type SucceededCall = { value: R; metadata: M; }; type FailedCall = { metadata: M; error: E; }; type Action = () => Promise>; type SettledResultWithMetadata = { ok: true; value: R; metadata: M; error: false; } | { ok: false; error: E; metadata: M; }; declare class ConcurrentCalls { #private; allowResultify: boolean; constructor(allowResultify: boolean); add(...calls: Action[]): this; resultifyAdd(...calls: ((() => R) | (() => Promise))[]): this; runAll({ delayStart }?: RunProps): Promise>; runAllSettled({ delayStart }?: RunProps): Promise<{ allFailed: boolean; failures: E[]; succeeded: R[]; total: number; aggregatedError: ConcurrentCallsAggregateError | null; }>; } /** * Executes multiple asynchronous calls concurrently and collects the results in * a easier to use format. * * @template R - The type of the result value. */ declare function concurrentCalls(): ConcurrentCalls; declare class ConcurrentCallsWithMetadata { #private; allowResultify: boolean; constructor(allowResultify: boolean); add(...calls: { fn: Action; metadata: M; }[]): this; resultifyAdd(...items: { fn: (() => R) | (() => Promise); metadata: M; }[]): this; runAll({ delayStart }?: RunProps): Promise[], FailedCall>>; runAllSettled({ delayStart }?: RunProps): Promise<{ allFailed: boolean; /** @deprecated Use failures property instead */ failed: FailedCall[]; failures: FailedCall[]; succeeded: SucceededCall[]; total: number; results: SettledResultWithMetadata[]; aggregatedError: ConcurrentCallsWithMetadataAggregateError | null; }>; } /** * Executes multiple asynchronous calls concurrently with metadata for each call * and collects the results in a easier to use format. * * @template M - The type of the call metadata. * @template R - The type of the result value. */ declare function concurrentCallsWithMetadata(): ConcurrentCallsWithMetadata; type ValueFromResult = R extends Result ? T : never; type ErrorFromResult = R extends Result ? E : never; /** * Executes multiple asynchronous result calls concurrently and collects the * results in a easier to use format. * * @template R - The type of the result function that will be called. */ declare function concurrentResultCalls Promise>>(): ConcurrentCalls>>, ErrorFromResult>>>; /** * Executes multiple asynchronous result calls concurrently with metadata for * each call and collects the results in a easier to use format. * * @template ResultFn - The type of the result function that will be called. */ declare function concurrentResultsWithMetadata Promise>>(): ConcurrentCallsWithMetadata>>, ErrorFromResult>>>; //#endregion export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata, concurrentResultCalls, concurrentResultsWithMetadata };