import type { ILogger } from '../../logger/index.js'; type Factory = () => Promise; export type DelayedTask = { /** Promise that resolves with the task result, or rejects if the task throws or is cancelled. */ readonly promise: Promise; /** Cancel the delayed task. If the task hasn't started yet, the promise rejects with a 'Cancelled' error. */ readonly cancel: () => void; }; export type TasksQueueOptions = { /** Delay in ms to wait after each task before starting the next one. Default: 0 */ delayBetweenTasks?: number; /** Called when a task throws. If provided, the error is NOT propagated to the enqueue() promise. */ onTaskError?: (error: unknown, name?: string) => void; }; export declare class TasksQueue { readonly limit: number; private readonly _items; private _running; private _logger; private readonly _delayBetweenTasks; private readonly _onTaskError; private readonly _delayedTasks; constructor(limit: number, options?: TasksQueueOptions); get isFull(): boolean; get running(): number; /** Number of tasks waiting in the queue (not including currently running) */ get pending(): number; addLogger(logger: ILogger): this; /** * Enqueue a task factory to run when a slot is available. * * **Note:** When `onTaskError` is provided in the constructor options and the factory throws, * the error is passed to `onTaskError` and the returned promise resolves with `undefined`. */ enqueue(factory: Factory, name?: string): Promise; /** Enqueue a task to run after `delay` ms. Returns a promise and a cancel function. */ enqueueDelayed(factory: Factory, delay: number, name?: string): DelayedTask; /** Remove all pending tasks from the queue. Does not cancel running tasks. Also cancels all delayed enqueues. * Pending enqueue() promises are rejected with a 'TasksQueue cleared' error so callers don't hang indefinitely. * Delayed tasks are cancelled and their promises are rejected with a 'Cancelled' error. */ clear(): void; private _runFactory; private _tryRunNext; } export {};