ag-charts-community
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
42 lines (41 loc) • 1.36 kB
TypeScript
export interface DeferredExecutorOptions {
/** Minimum time to wait before execution can begin (ms). Default: 0 */
minimumDelay?: number;
/** Maximum time to wait before forcing execution (ms). Default: 100 */
timeout?: number;
}
/**
* Manages deferred execution of computations, allowing work to be scheduled
* for idle time while supporting on-demand execution and cancellation.
*
* Uses `requestIdleCallback` when available, falling back to `setTimeout`.
*/
export declare class DeferredExecutor<T> {
private readonly minimumDelay;
private readonly timeout;
private pending?;
private delayTimeoutId?;
private idleCallbackId?;
constructor(options?: DeferredExecutorOptions);
/**
* Schedule a computation for deferred execution.
* If something is already pending, it will be cancelled first.
*/
schedule(computation: () => T, onComplete: (result: T) => void): void;
/**
* Force immediate execution if pending.
* @returns The computation result, or undefined if nothing was pending.
*/
demand(): T | undefined;
/**
* Cancel any pending execution without running it.
*/
cancel(): void;
/**
* Check if there's pending work.
*/
isPending(): boolean;
private scheduleIdleCallback;
private cancelScheduled;
private execute;
}