haystack-nclient
Version:
Project Haystack Network Client
33 lines (32 loc) • 738 B
TypeScript
/**
* A mutex object to prevent concurrent access of
* long running asynchronous calls.
*
* ```typescript
* const mutex = new Mutex()
*
* mutex.runSequential(async (): Promise<void> => {
* if (await longRunningNetworkCall()) {
* // Do something...
* }
* })
* ```
*/
export declare class Mutex {
#private;
/**
* Run a task exclusively and sequentially.
*
* @param task The task to run.
* @return A Promise that resolves to a result.
*/
runSequential<T>(task: () => Promise<T>): Promise<T>;
/**
* Wait for all tasks to complete.
*/
wait(): Promise<void>;
/**
* @returns True if the mutex has outstanding tasks running.
*/
isLocked(): boolean;
}