frdrk-js-semaphore

0.3.1 • Public • Published

frdrk-js-semaphore - Syncronization Using Promises (fork)

License Travis CI Coverage Status Commitizen

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();
});

License

MIT License © Codevor

Package Sidebar

Install

npm i frdrk-js-semaphore

Weekly Downloads

0

Version

0.3.1

License

MIT

Unpacked Size

29.2 kB

Total Files

7

Last publish

Collaborators

  • frdrk