async-sequential-runner
Version:
TypeScript class for running async tasks to completion in sequence.
31 lines (30 loc) • 1.08 kB
TypeScript
/**
* Runs async tasks sequentially.
*/
export declare class AsyncSequentialRunner<R> {
private activeIterator?;
private triggers?;
/**
* Runs a task after previous scheduled operations
* have run, returning a promise with the result.
* @param operation A function that will be called to perform
* work, with a boolean indicating if more operations are scheduled.
*/
run(task: (hasMore: boolean) => Promise<R>): Promise<R>;
/**
* Creates a trigger with a promise that will complete after the
* next task has completed. The trigger can be cancelled by
* calling the cancel function. Useful to trigger polling functions
* that can schedule a task when the trigger promise completes.
*/
taskCompleteTrigger(): {
cancel: () => void;
promise: Promise<void>;
};
/**
* Returns whether there are more tasks scheduled or triggers waiting
* for task completion, useful for determining when to clean up
* references to the runner.
*/
hasTasksOrTriggers(): boolean;
}