thorish
Version:
This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.
32 lines (31 loc) • 966 B
TypeScript
export type WaitNextTaskFn<T> = () => Promise<() => T>;
export type AggregateRunnerTask<T> = (signal: AbortSignal, nextTask: WaitNextTaskFn<T>) => any;
export type AggregateRunner<T> = {
/**
* Enqueue this data for the runner.
*
* This does not start the task automatically.
*/
enqueue(signal: AbortSignal, data: T): void;
/**
* Is the aggregate runner active?
*/
active(): boolean;
/**
* Are there any pending items to work on?
* The runner might still be processing something.
*/
hasPending(): boolean;
/**
* Starts the runner, or returns the result of an already active runner.
*/
start(): Promise<void>;
/**
* Returns all pending items here.
*/
pending(): Iterable<T>;
};
/**
* Runs an aggregate task based on other signal-bound tasks passed in here.
*/
export declare function buildAggregateRunner<T>(runner: AggregateRunnerTask<T>): AggregateRunner<T>;