JSPM

frdrk-js-semaphore

0.3.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q22862F
  • License MIT

Semaphore Implementation for JS

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)

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