@trenskow/semaphore

0.2.0 • Public • Published

@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.

Readme

Keywords

Package Sidebar

Install

npm i @trenskow/semaphore

Weekly Downloads

4

Version

0.2.0

License

BSD-2-Clause

Unpacked Size

4.27 kB

Total Files

7

Last publish

Collaborators

  • trenskow