import { type PromiseWithResolvers } from "../promises.ts"; export type TaskProcessing = Promise; export type TaskWaiting = () => Promise; export type Task = TaskProcessing | TaskWaiting; export type TaskResult = { ok: T; } | { err: U; }; export type TaskResultWithKey = TaskResult & { key: number; }; export type ProcessingTaskResultWithKey = Promise>; export declare function unwrapTaskResult(result: TaskResult): T | U; /** * Perform all tasks within given concurrency. * @param limit Concurrency limit * @param tasks Tasks to perform all * */ export declare function processAllGeneratorTasksWithConcurrencyLimit(limit: number, tasks: AsyncGenerator, undefined, unknown>): AsyncGenerator, void, unknown>; export declare function pipeGeneratorToGenerator(generator: AsyncGenerator, callback: (obj: T) => Promise): AsyncGenerator>; export declare function pipeArrayToGenerator(array: T[], callback: (obj: T) => Promise): Generator>; /** * Perform all tasks within given concurrency. * @param limit Concurrency limit * @param tasks Tasks to perform all * */ export declare function processAllTasksWithConcurrencyLimit(limit: number, tasks: Task[]): AsyncGenerator, void, unknown>; /** * Perform all tasks and returns all result by keeping the order. * @param limit Concurrency limit * @param tasks Tasks to perform all * @returns */ export declare function mapAllTasksWithConcurrencyLimit(limit: number, tasks: Task[]): Promise[]>; export declare function scheduleTask(key: string, timeout: number, proc: () => Promise | void, skipIfTaskExist?: boolean): void; export declare function cancelTask(key: string): void; export declare function cancelAllTasks(): void; export declare function setPeriodicTask(key: string, timeout: number, proc: () => Promise | void): void; export declare function cancelPeriodicTask(key: string): void; export declare function cancelAllPeriodicTask(): void; export declare function waitForTimeout(key: string, timeout: number): Promise; export declare function finishWaitingForTimeout(key: string, hasTimeout?: boolean): void; export declare function finishAllWaitingForTimeout(prefix: string, hasTimeout: boolean): void; export declare function isWaitingForTimeout(key: string): boolean; export type ResolverWithKey = { key: string; resolver: PromiseWithResolvers; }; /** * @deprecated * Use shareRunningResult instead. * @param key * @param proc * @returns */ export declare function sharedTask(key: string, proc: () => Promise): Promise; export declare function wrapFunctionAsShared

(proc: (...p: P) => Promise): (...p: P) => Promise;