UNPKG

node-apparatus

Version:

A mix of common components needed for awesome node experience

35 lines (34 loc) 1.18 kB
export declare enum SpinWaitLockState { Acquired = 0, Condition = 2 } /** * A spin-wait lock. Can be used for single threaded & multi threaded synchronization. */ export declare class SpinWaitLock { private readonly serializedLock; private readonly LOCK_INDEX; private readonly lock; private readonly contextQueue; /** * @param serializedLock The serialized lock to use, should pass output of serialize method, default is a new SharedArrayBuffer(4). */ constructor(serializedLock?: SharedArrayBuffer); /** * Serializes the lock, used for passing the lock between threads. * @returns The serialized lock, a shared buffered instance. */ serialize(): SharedArrayBuffer; /** * Acquires the lock. * @param spinTime The time to wait between attempts to acquire the lock. * @param spinExitCondition The condition to exit the spin-wait loop. * @returns A promise that resolves to the state of the lock. */ acquire(spinTime?: number, spinExitCondition?: () => boolean): Promise<SpinWaitLockState>; /** * Releases the lock. * @returns void */ release(): void; }