frdrk-js-semaphore
v0.3.1
Published
Semaphore Implementation for JS
Downloads
2
Readme
frdrk-js-semaphore - Syncronization Using Promises (fork)
js-semaphore
is a simple Semaphore implementation using Promises for JavaScript aplications.
Installation
js-semaphore
is available with npm/yarn:
$ npm install frdrk-js-semaphore --save
Usage
With require
const Semaphore = require('frdrk-js-semaphore').Semaphore;
// Semaphore with 1 resource = Mutex
const semaphore = Semaphore();
// Semaphore with 1 resource, starting at 0 value
const semaphore = Semaphore({ resource: 1, start: 0 });
// Semaphore with 3 resources
const semaphore = Semaphore({ resource: 3 });
// acquire the semaphore
semaphore.acquire().then(() => {
// Your code goes here
const x = 2 + 3;
// remember to release the semaphore at the end of your usage
semaphore.release();
});