/** * Promise.all with automatic dependency optimization and full type inference * * Usage: * const { a, b, c } = await all({ * a() { return 1 }, * async b() { return 'hello' }, * async c() { return (await this.$.a) + 10 } * }) */ type TaskResult = T extends (...args: any[]) => infer R ? Awaited : never; type AllResult any>> = { [K in keyof T]: TaskResult; }; type SettledFulfilled = { status: 'fulfilled'; value: T; }; type SettledRejected = { status: 'rejected'; reason: any; }; type SettledResult = SettledFulfilled | SettledRejected; type AllSettledResult any>> = { [K in keyof T]: SettledResult>; }; type ExecutionOptions = { debug?: boolean; signal?: AbortSignal; }; /** * Execute tasks with automatic dependency resolution. * * @example * const { a, b, c } = await all({ * async a() { return 1 }, * async b() { return 'hello' }, * async c() { return (await this.$.a) + 10 } * }) * * @example * // With debug mode * const result = await all({ * async a() { return 1 }, * async b() { return (await this.$.a) + 10 } * }, { debug: true }) * * @example * // With auto-abort on failure - this.$signal is aborted when any sibling task fails * const result = await all({ * async a() { return fetchWithSignal(this.$signal) }, * async b() { throw new Error('fails') }, // This will abort tasks a and c * async c() { return fetchWithSignal(this.$signal) } * }) * * @example * // With external signal * const controller = new AbortController() * const result = await all({ * async a() { return fetchWithSignal(this.$signal) } * }, { signal: controller.signal }) */ declare function all>(tasks: T & ThisType<{ $: { [K in keyof T]: ReturnType extends Promise ? Promise : Promise>; }; $signal: AbortSignal; }> & { [K in keyof T as T[K] extends Function ? K : `Error: task \`${K & string}\` is not a function`]-?: T[K]; }, options?: ExecutionOptions): Promise>; /** * Execute tasks with automatic dependency resolution, returning settled results for all tasks. * Unlike `all`, this will never reject - failed tasks will be included in the result with their error. * * @example * const { a, b, c } = await allSettled({ * async a() { return 1 }, * async b() { throw new Error('failed') }, * async c() { return (await this.$.a) + 10 } * }) * // a: { status: 'fulfilled', value: 1 } * // b: { status: 'rejected', reason: Error('failed') } * // c: { status: 'fulfilled', value: 11 } * * @example * // With debug mode * const result = await allSettled({ * async a() { return 1 }, * async b() { throw new Error('failed') } * }, { debug: true }) */ declare function allSettled>(tasks: T & ThisType<{ $: { [K in keyof T]: ReturnType extends Promise ? Promise : Promise>; }; $signal: AbortSignal; }> & { [P in keyof T]: T[P] extends (...args: any[]) => any ? T[P] : never; }, options?: ExecutionOptions): Promise>; /** * Execute tasks with automatic dependency resolution and support for early exit. * The first task to call `this.$end(value)` determines the return value. * * @example * // Early exit from first task * const f = await flow({ * async task1() { * this.$end(42) // Immediately ends, f = 42 * return 1 // Never reached * }, * async task2() { * const r = await this.$.task1 // Throws (silently caught) * return r + 10 * }, * }) * // f = 42 * * @example * // Conditional early exit * const f = await flow({ * async task1() { * const cached = await checkCache() * if (cached) this.$end(cached) // Early exit if cached * return await fetchFromApi() * }, * async task2() { * const data = await this.$.task1 * this.$end(transform(data)) * }, * }) * * @example * // Race between tasks * const f = await flow({ * async fast() { * await sleep(100) * this.$end('fast won') * }, * async slow() { * await sleep(1000) * this.$end('slow won') * }, * }) * // f = 'fast won' */ declare function flow = Record>(tasks: T & ThisType<{ $: { [K in keyof T]: ReturnType extends Promise ? Promise : Promise>; }; $signal: AbortSignal; $end: (value: R) => never; }> & { [K in keyof T as T[K] extends Function ? K : `Error: task \`${K & string}\` is not a function`]-?: T[K]; }, options?: ExecutionOptions): Promise; export { all, allSettled, flow }; //# sourceMappingURL=index.d.ts.map