Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mutexlight

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mutexlight

minimal mutex library for asynchronous locking

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 27 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc