RenaiApp/src/main/modules/mutex/i-mutex.d.ts

20 lines
766 B
TypeScript

/**
* A mutex (mutual exclusion) is a lock which enforces limited access to a resource in asynchronous/multi-threaded environments.
*
* Acquiring this lock returns a release function function (via promise) which needs to be called to release the lock again.
*/
interface IMutex {
/**
* acquires the lock and returns a Promise with the release function to be called when the lock shall be released.
* This release function needs to be called or the lock will never release and execution of subsequent consumers will not take place.
* Always think about possible error states and release the lock accordingly.
*/
acquire(): Promise<Mutex.ReleaseFunction>;
isLocked(): boolean;
}
declare namespace Mutex {
type ReleaseFunction = () => void;
}