@trenskow/semaphore
v0.2.14
Published
A small library for waiting in JavaScript.
Readme
@trenskow/semaphore
A small library for waiting in JavaScript.
Usage
Create a new semaphore like below.
const Semaphore = require('@trenskow/semaphore');
const mySemaphore = new Semaphore();Waiting
To wait do as below.
await mySemaphore.wait();Signalling and broadcasting
To signal (from another place) that one of the waiters can continue, do as below.
mySemaphore.signal();– or to broadcast to all awaiters to conitnue.
mySemaphore.broadcast();Errors
You can also reject all awaiters with an error.
mySemphore.reject(myError);LICENSE
See license in LICENSE.
