export type AsyncStatus = 'initial' | 'pending' | 'success' | 'failure'; /** * Waits for the given `duration` before resolving. */ export declare const wait: (duration?: number) => Promise; /** * Checks if `value` is a `Promise` (or thenable). */ export declare const is_promise: (value: unknown) => value is Promise; /** * A deferred object with a promise and its resolve/reject handlers. */ export interface Deferred { promise: Promise; resolve: (value: T) => void; reject: (reason: any) => void; } /** * Creates an object with a `promise` and its `resolve`/`reject` handlers. */ export declare const create_deferred: () => Deferred; /** * Runs a function on each item with controlled concurrency. * Like `map_concurrent` but doesn't collect results (more efficient for side effects). * * @param concurrency - maximum number of concurrent operations * @param signal - optional `AbortSignal` to cancel processing * @throws Error if `concurrency < 1` * * @example * ```ts * await each_concurrent( * file_paths, * 5, // max 5 concurrent deletions * async (path) => { await unlink(path); }, * ); * ``` */ export declare const each_concurrent: (items: Iterable, concurrency: number, fn: (item: T, index: number) => Promise | void, signal?: AbortSignal) => Promise; /** * Maps over items with controlled concurrency, preserving input order. * * @param concurrency - maximum number of concurrent operations * @param signal - optional `AbortSignal` to cancel processing * @returns array of results in same order as input * @throws Error if `concurrency < 1` * * @example * ```ts * const results = await map_concurrent( * file_paths, * 5, // max 5 concurrent reads * async (path) => readFile(path, 'utf8'), * ); * ``` */ export declare const map_concurrent: (items: Iterable, concurrency: number, fn: (item: T, index: number) => Promise | R, signal?: AbortSignal) => Promise>; /** * Like `map_concurrent` but collects all results/errors instead of failing fast. * Returns an array of settlement objects matching the `Promise.allSettled` pattern. * * On abort, resolves with partial results: completed items keep their real settlements, * in-flight and un-started items are settled as rejected with the abort reason. * * @param concurrency - maximum number of concurrent operations * @param signal - optional `AbortSignal` to cancel processing * @returns array of `PromiseSettledResult` objects in input order * @throws Error if `concurrency < 1` * * @example * ```ts * const results = await map_concurrent_settled(urls, 5, fetch); * for (const [i, result] of results.entries()) { * if (result.status === 'fulfilled') { * console.log(`${urls[i]}: ${result.value.status}`); * } else { * console.error(`${urls[i]}: ${result.reason}`); * } * } * ``` */ export declare const map_concurrent_settled: (items: Iterable, concurrency: number, fn: (item: T, index: number) => Promise | R, signal?: AbortSignal) => Promise>>; /** * Async semaphore for concurrency limiting. * * With `Infinity` permits, `acquire()` always resolves immediately. */ export declare class AsyncSemaphore { #private; /** * @throws Error if `permits < 0` */ constructor(permits: number); acquire(): Promise; release(): void; } //# sourceMappingURL=async.d.ts.map