0.1.15 ā¢ Published 2 months ago
@trenskow/semaphore v0.1.15
@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.