Package Exports
- frdrk-js-semaphore
- frdrk-js-semaphore/dist/js-semaphore.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (frdrk-js-semaphore) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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 --saveUsage
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();
});