parallel-universe
Version:
The set of async flow control structures and promise utils.
20 lines (19 loc) • 646 B
TypeScript
/**
* Promise-based lock implementation.
*
* When someone tries to acquire a {@link Lock} they receive a promise for a release callback that is fulfilled as soon
* as previous lock owner invokes their release callback.
*
* @see https://en.wikipedia.org/wiki/Lock_(computer_science) Lock (computer science)
*/
export declare class Lock {
private _promise?;
/**
* `true` if {@link Lock} was acquired and wasn't released yet.
*/
get isLocked(): boolean;
/**
* Waits for the {@link Lock} to become available and fulfills it with the callback that releases the lock.
*/
acquire(): Promise<() => void>;
}