3.0.0 • Published 1 month ago

bare-atomics v3.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 month ago

bare-atomics

Native synchronization primitives for JavaScript.

npm i bare-atomics

API

Mutex

const mutex = new Mutex([options])

Options include:

{
  recursive: false
}

const mutex = Mutex.from(handle[, options])

Options are the same as new Mutex().

mutex.handle

A SharedArrayBuffer with the underlying mutex handle.

mutex.held

Whether or not the current thread currently holds the mutex.

mutex.lock()

const success = mutex.tryLock()

mutex.unlock()

mutex.destroy()

Semaphore

const semaphore = new Semaphore(value)

const semaphore = Semaphore.from(handle)

semaphore.handle

A SharedArrayBuffer with the underlying semaphore handle.

semaphore.wait()

const success = semaphore.tryWait()

semaphore.post()

semaphore.destroy()

Condition

const condition = new Condition()

const condition = Condition.from(handle)

condition.handle

A SharedArrayBuffer with the underlying condition handle.

const success = condition.wait(mutex[, timeout])

condition.signal()

condition.broadcast()

condition.destroy()

Barrier

const barrier = new Barrier(count)

const barrier = Barrier.from(handle)

barrier.handle

A SharedArrayBuffer with the underlying barrier handle.

const success = barrier.wait()

barrier.destroy()

License

Apache-2.0

3.0.0

1 month ago

2.0.4

2 months ago

2.0.3

3 months ago

2.0.2

3 months ago

2.0.1

3 months ago

2.0.0

6 months ago

1.0.0

11 months ago