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

30 lines
962 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 MutexInterface {
/**
* 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>;
/**
* release the lock and execute the next consumer.
*/
release(): void;
/**
* release the lock and do not allow any current consumers to execute.
*/
reset(): void;
isLocked(): boolean;
}
declare namespace Mutex {
type ReleaseFunction = () => void;
}