/** * Options for the {@linkcode OperationQueue}. */ export interface OperationQueueOptions { /** * The maximum number of times the operation queue will iterate over its operations before throwing an error. * * Operations can enqueue additional operations on to the queue. When this happens, the operation queue will finish * running the current iteration of operations, and then start running the next iteration (using the same priority * semantics). * * _Note_: It's best to keep this number as low as possible, as it will increase the amount of time it takes to run * the operation queue and the likelihood of running into an infinite loop. * * @default 1 */ maxIterations: number; /** * The default priority for operations that are enqueued without an explicit priority. * * The lower the number, the higher the priority. Operations with higher priority will be run before operations with * lower priority. If two or more operations have the same priority, they will be run concurrently. * * @default Infinity */ defaultPriority: number | bigint; /** * The minimum priority for operations that are enqueued. * * @default -Infinity */ minPriority: number | bigint; /** * The maximum priority for operations that are enqueued. * * @default Infinity */ maxPriority: number | bigint; /** * Specifies whether the operation queue should throw an error when any of the operations throw an error. * * If this is set to `false`, the operation queue will swallow the error and continue. * * @default true */ throwOnError: boolean; } /** * Options for {@linkcode OperationQueue.enqueue}. */ export interface EnqueueOptions { /** * The priority of the operation. The lower the number, the higher the priority. * * Operations with higher priority will be run before operations with lower priority. If two or more operations have * the same priority, they will be run concurrently. * * @default OperationQueueOptions.defaultPriority */ priority: number | bigint; /** * Specifies whether operations with the same name should be replaced or not. * * _Note_: Any operations that were enqueued with `replace: false` will be replaced if an operation with the same name * is later enqueued with `replace: true`. * * @default true */ replace?: boolean; } interface Operation unknown> { name: string; options: EnqueueOptions; fn: Fn; } /** * Concurrent callback queue with a priority system. */ export declare class OperationQueue unknown> { readonly name: string; private unorderedOperations; private readonly options; private readonly logger; /** * @param name The name of the operation queue. (preferably kebab-case) * @param options The options for the operation queue. */ constructor(name: string, options?: Partial); /** * The number of operations in the queue. */ get length(): number; /** * The current operations in the queue, grouped and sorted by priority. */ get operations(): Operation[][]; /** * The names of the operations in the queue, grouped and sorted by priority. */ get operationNames(): string[][]; /** * Clears all operations from the queue. */ clear(): void; /** * Adds an operation to the queue. If the operation already exists, it will be replaced. * * @param name The name of the operation. (preferably kebab-case) * @param fn The operation to enqueue. */ enqueue(name: string, fn: Fn): void; /** * Adds an operation to the queue. * * @param name The name of the operation. (preferably kebab-case) * @param options Options for the operation. * @param fn The operation to enqueue. */ enqueue(name: string, options: Partial, fn: Fn): void; /** * Runs the queue. * * @param args The arguments to pass to the operations. * @returns A promise that resolves when all operations have completed and the queue is empty. */ run(...args: Parameters): Promise; private runIteration; } export {};