UNPKG

@dhlx/rwlock-shared

Version:

A simple implementation of a read-write lock with shared read

19 lines (18 loc) 719 B
export declare class ReadWriteLock { state: Int32Array; static readonly READERS = 0; static readonly WRITER = 1; static readonly WAITERS = 2; timeout: number; constructor(sharedBuffer: SharedArrayBuffer, config?: { timeout?: number; }); /** Acquire a read lock (async). Blocks if a writer is active or waiting. */ readLock(): Promise<void>; /** Release a read lock. Wakes a waiting writer if this was the last reader. */ readUnlock(): void; /** Acquire a write lock (async). Blocks until no readers or writers are active. */ writeLock(): Promise<void>; /** Release the write lock. Wakes the next waiter(s) based on priority. */ writeUnlock(): void; }