import ManagementRoomOutput from "../managementroom/ManagementRoomOutput";
import { Result } from "@gnuxie/typescript-result";
export type TaskFactory<T> = () => Promise<Result<T>>;
/**
 * A queue for backgrounding tasks without hammering servers too much.
 */
export declare class ThrottlingQueue {
    private managementRoomOutput;
    /**
     * How long we should wait between the completion of a tasks and the start of the next task.
     * Any >=0 number is good.
     */
    private delayMS;
    /**
     * The pending tasks.
     */
    private _tasks;
    /**
     * A timeout for the next task to execute.
     */
    private timeout;
    /**
     * Construct an empty queue.
     *
     * This queue will start executing whenever `push()` is called and stop
     * whenever it runs out of tasks to execute.
     *
     * @param delayMS The default delay between executing two tasks, in ms.
     */
    constructor(managementRoomOutput: ManagementRoomOutput, 
    /**
     * How long we should wait between the completion of a tasks and the start of the next task.
     * Any >=0 number is good.
     */
    delayMS: number);
    /**
     * Stop the queue, make sure we can never use it again.
     */
    dispose(): void;
    /**
     * The number of tasks waiting to be executed.
     */
    get length(): number;
    /**
     * Push a new task onto the queue.
     *
     * @param task Some code to execute.
     */
    push<T>(task: TaskFactory<T>): void;
    /**
     * Block a queue for a number of milliseconds.
     *
     * This method is meant typically to be used by a `Task` that receives a 429 (Too Many Requests) to reschedule
     * itself for later, after giving the server a little room to breathe. If you need this, do not forget to
     * re-`push()` with the failing `Task`. You may call `block()` and `push()` in either order.
     *
     * @param durationMS A number of milliseconds to wait until resuming operations.
     */
    block(durationMS: number): void;
    /**
     * Start the loop to execute pending tasks.
     *
     * Does nothing if the loop is already started.
     */
    private start;
    /**
     * Stop the loop to execute pending tasks.
     *
     * Does nothing if the loop is already stopped. A loop stopped with `stop()` may be
     * resumed by calling `push()` or `start()`.
     */
    private stop;
    /**
     * Change the delay between completion of an event and the start of the next event.
     *
     * This will be used next time a task is completed.
     */
    setDelayMS(delayMS: number): void;
    /**
     * Execute one step of the loop, then prepare the following step.
     *
     * 1. If there is no task, do nothing and stop.
     * 2. Otherwise, execute task.
     * 3. Once task is complete (whether succeeded or failed), retrigger the loop.
     */
    private step;
    /**
     * Return `tasks`, unless the queue has been disposed of.
     */
    private get tasks();
}
//# sourceMappingURL=ThrottlingQueue.d.ts.map