Native synchronization primitives for JavaScript.
npm i bare-atomics
const mutex = new Mutex([options])Options include:
{
recursive: false
}
const mutex = Mutex.from(handle[, options])Options are the same as new Mutex().
mutex.handleA SharedArrayBuffer with the underlying mutex handle.
mutex.heldWhether or not the current thread currently holds the mutex.
mutex.lock()const success = mutex.tryLock()mutex.unlock()mutex.destroy()const semaphore = new Semaphore(value)const semaphore = Semaphore.from(handle)semaphore.handleA SharedArrayBuffer with the underlying semaphore handle.
semaphore.wait()const success = semaphore.tryWait()semaphore.post()semaphore.destroy()const condition = new Condition()const condition = Condition.from(handle)condition.handleA SharedArrayBuffer with the underlying condition handle.
const success = condition.wait(mutex[, timeout])condition.signal()condition.broadcast()condition.destroy()const barrier = new Barrier(count)const barrier = Barrier.from(handle)barrier.handleA SharedArrayBuffer with the underlying barrier handle.
const success = barrier.wait()barrier.destroy()Apache-2.0