mutexlight

1.0.4 • Public • Published

mutexlight

mutexlight is a zero-dependencies minimal mutex library. Mutexes are used to obtain exclusive locks to certain resources which are accessed asynchronously.

Requirements

It runs inside any webbrowser or node environment that supports promises.

Basic usage

The following sample code should speak for itself:

const mutexlight = require("mutexlight");

const mutex = new mutexlight();

async function runme() {
  const release = await mutex.acquire();        // Acquire mutex lock
  // Do some stuff
  release();                                    // Release mutex lock
}

runme();

Reference documentation

API

Exposed API-list:

  • new mutexlight()
    Creates a new mutex.
  • this.acquire(tryonly)
    Returns a promise that resolves once the mutex lock has been acquired. The promise resolves to a release function which needs to be called as soon as the mutex lock needs to be released (acquired locks that are not explicitly released will stay stuck in locked state indefinitely). If trylock is true, the promise will resolve to zero immediately if the mutex lock has already been acquired.

References

Card-carrying member of the zerodeps movement.

Package Sidebar

Install

npm i mutexlight

Weekly Downloads

7

Version

1.0.4

License

(ISC OR GPL-3.0)

Unpacked Size

2.51 kB

Total Files

3

Last publish

Collaborators

  • buglessrb