UNPKG

@ma3-pro-plugins/ma3-pro-plugins-lib

Version:
29 lines (28 loc) 975 B
import { Logger } from './Logger'; export type IMutex = { /** * Thread id as a string */ tid: string; /** * Locks the mutex. * If the mutex is already locked, the calling thread will be suspended until the mutex is unlocked. * If the mutex is locked by the current thread, then it returns immediately with 'ok' * @returns 'ok' if the lock was acquired, 'timeout' if the lock could not be acquired within the timeout period. */ lock(): 'ok' | 'timeout'; /** * Tries to lock the mutex without blocking. * @returns true if the lock was acquired, false otherwise */ tryLock(): boolean; unlock(): void; destroy(): void; isDestroyed(): boolean; setLog(newLog: Logger): void; }; /** * A mutex implementaiton using coroutines. */ export declare function CoroutineMutex(log?: Logger, onDestroy?: (tid: string) => void): IMutex; export type CoroutineMutex = ReturnType<typeof CoroutineMutex>;