@codesandbox/sdk
Version:
The CodeSandbox SDK
22 lines (21 loc) • 802 B
TypeScript
export type PromiseCallback<T> = () => Promise<T>;
export type QueueCallback<T> = PromiseCallback<T> | (() => T);
/**
* SerialQueue runs 1 promise at a time, very useful for reducing load and working around lock files
*/
export declare class SerialQueue {
private name;
private debug;
private items;
private isProcessing;
constructor(name: string, debug?: boolean);
private processQueue;
/**
* Add a new promise callback to the queue
*
* in case you provide a key it will be used to de-duplicate against existing items in the queue
* if there is an existing item, the callback of that item will be used and this function will
* return the result of that callback instead
*/
add<T>(callback: QueueCallback<T>, key?: string): Promise<T>;
}