import { LDLogger } from '@launchdarkly/js-sdk-common'; /** * Represents a task that has been shed from the queue. * This task will never be executed. */ export interface ShedTask { status: 'shed'; } /** * Represents a task that has been ran to completion. */ export interface CompletedTask { status: 'complete'; result: TTaskResult; } /** * Represents a task that has errored. */ export interface ErroredTask { status: 'error'; error: Error; } /** * Represents the result of a task. */ export type TaskResult = CompletedTask | ErroredTask | ShedTask; export interface Task { /** * Method ran before the task is executed or shed. */ before?: () => Promise; /** * Execute the task. This is not ran if the task is shed. * @returns The result of the task. */ execute: (beforeResult?: TBeforeResult) => Promise; /** * Method ran after the task is executed or shed. * @param result The result of the task. */ after?: (result: TaskResult, beforeResult?: TBeforeResult) => void; } /** * An asynchronous task queue with the ability to replace pending tasks. * * This is useful when you have asynchronous operations which much execute in order, and for cases where intermediate * operations can be discarded. * * For instance, the SDK can only have one active context at a time, if you request identification of many contexts, * then the ultimate state will be based on the last request. The intermediate identifies can be discarded. * * This queue will always begin execution of the first item added to the queue, at that point the item itself is not * queued, but active. If another request is made while that item is still active, then it is added to the queue. * A third request would then replace the second request if the second request had not yet become active, and it was * sheddable. * * Once a task is active the queue will complete it. It doesn't cancel tasks that it has started, but it can shed tasks * that have not started. * * TTaskResult Is the return type of the task to be executed. Tasks accept no parameters. So if you need parameters * you should use a lambda to capture them. * * Exceptions from tasks are always handled and the execute method will never reject a promise. * * Queue management should be done synchronously. There should not be asynchronous operations between checking the queue * and acting on the results of said check. */ export declare function createAsyncTaskQueue(logger?: LDLogger): { /** * Execute a task using the queue. * * @param task The async function to execute. * @param sheddable Whether the task can be shed from the queue. * @returns A promise that resolves to the result of the task. */ execute(task: Task, sheddable?: boolean): Promise>; /** * Returns the number of pending tasks in the queue. * Intended for testing purposes only. * * @internal * @returns The number of pending tasks in the queue. */ pendingCount(): number; }; //# sourceMappingURL=AsyncTaskQueue.d.ts.map