import { GenericAsyncCallback, GenericCallback } from "./models.mjs"; //#region src/queue.d.ts /** * A queue that can be used to manage (a)synchronous tasks with a specific key */ declare class KeyedQueue, CallbackResult> { #private; /** * Get keys of all active queues */ get active(): string[]; /** * Does the queue automatically start when the first item is added? */ get autostart(): boolean; /** * Maximum number of runners to process the queue concurrently */ get concurrency(): number; /** * Get keys of all empty queues */ get empty(): string[]; /** * Get keys of all full queues */ get full(): string[]; /** * Number of items in all queues */ get items(): Record; /** * Keys of all queues */ get keys(): string[]; /** * Maximum number of items allowed in the queue */ get maximum(): number; /** * Are all queues paused? */ get paused(): string[]; /** * Number of queues */ get queues(): number; constructor(callback: GenericAsyncCallback, options: Required); /** * Queue an item for a specific key * * @param key Key to queue the item for * @param parameters Parameters to use when item runs * @param signal Optional signal to abort the item * @returns Queued item */ add(key: string, parameters: Tail, signal?: AbortSignal): Queued; /** * Clear all items for a specific key _(or all items for all keys, if no key is provided)_ * * @param key Optional key to clear the queue for */ clear(key?: string): void; /** * Get the queue for a specific key * * @param key Key to get the queue for * @returns Queue for the key, or `undefined` if it doesn't exist */ get(key: string): Queue, CallbackResult> | undefined; /** * Pause the queue for a specific key _(or all queues, if no key is provided)_ * * @param key Optional key to pause the queue for */ pause(key?: string): void; /** * Remove a specific item for a specific key * * @param key Key to remove the item for * @param id ID of the item to remove */ remove(key: string, id: number): void; /** * Remove a queue and its items for a specific key * * _(To remove all items for a specific key, use `clear()` instead)_ * * @param key Key to remove the queue for */ remove(key: string): void; /** * Remove all queues and their items */ remove(): void; /** * Resume the queue for a specific key _(or all queues, if no key is provided)_ * * @param key Optional key to resume the queue for */ resume(key?: string): void; } /** * A queue that can be used to manage (a)synchronous tasks */ declare class Queue, CallbackResult> { #private; /** * Is the queue active? */ get active(): boolean; /** * Does the queue automatically start when the first item is added? */ get autostart(): boolean; /** * Maximum number of runners to process the queue concurrently */ get concurrency(): number; /** * Is the queue empty? */ get empty(): boolean; /** * Is the queue full? */ get full(): boolean; /** * Maximum number of items allowed in the queue */ get maximum(): number; /** * Is the queue paused? */ get paused(): boolean; /** * Number of items in the queue */ get size(): number; constructor(callback: GenericAsyncCallback, options: Required, key?: string); /** * Add an item to the queue * * @param parameters Parameters to use when item runs * @param signal Optional signal to abort the item * @returns Queued item */ add(parameters: CallbackParameters, signal?: AbortSignal): Queued; /** * Remove and reject all items in the queue */ clear(): void; /** * Pause the queue * * - Currently running items will not be stopped * - New added items will not run until the queue is resumed */ pause(): void; /** * Remove and reject a specific item in the queue * * @param id ID of queued item */ remove(id: number): void; /** * Resume the queue */ resume(): void; } /** * An error thrown by the Queue when an operation fails */ declare class QueueError extends Error { constructor(message: string); } type QueueOptions = { /** * Automatically start processing the queue when the first item is added _(defaults to `true`)_ */ autostart?: boolean; /** * Number of runners to process the queue concurrently _(defaults to `1`)_ */ concurrency?: number; /** * Maximum number of items allowed in the queue _(defaults to `0`, which means no limit)_ */ maximum?: number; }; /** * A queued item */ type Queued = { /** * ID of the queued item _(can be used to remove it from the queue)_ */ readonly id: number; /** * Queued promise */ readonly promise: Promise>; }; type QueuedResult = { /** * Has the queue finished processing all items? */ finished: boolean; /** * Result for the queued promise */ value: Value; }; type Tail = Values extends [infer _, ...infer Rest] ? Rest : never; declare function keyedQueue(callback: Callback, options?: QueueOptions): KeyedQueue, Awaited>>; /** * Create a queue for an asynchronous callback function * * @param callback Callback function for queued items * @param options Queue options * @returns Queue instance */ declare function queue Promise>(callback: Callback, options?: QueueOptions): Queue, Awaited>>; /** * Create a queue for a synchronous callback function * * @param callback Callback function for queued items * @param options Queue options * @returns Queue instance */ declare function queue(callback: Callback, options?: QueueOptions): Queue, ReturnType>; declare namespace queue { var keyed: typeof keyedQueue; } //#endregion export { type KeyedQueue, type Queue, type QueueError, type QueueOptions, type Queued, type QueuedResult, keyedQueue, queue };