A small library for waiting in JavaScript.
Create a new semaphore like below.
const Semaphore = require('@trenskow/semaphore');
const mySemaphore = new Semaphore();
To wait do as below.
await mySemaphore.wait();
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();
You can also reject all awaiters with an error.
mySemphore.reject(myError);
See license in LICENSE.