npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mutex-async

v1.0.2

Published

A javascript mutex designed for async/await

Readme

Mutex Async

A basic javascript library that provides an asynchronous mutex. Designed for use with for async/await. It supports a variable number of locks at a time.

Installation

npm install mutex-async

Usage

const mutexAsync = require('mutex-async');

const mutex = new mutexAsync.Mutex();

async function criticalSection() {
	let unlock = await mutex.lock();
	try {
		// Critical section code here
	} catch(err) {
		
	}
	await unlock();
}

// or

async function criticalSection() {
	await mutex.run(async () => {
		// Critical section code here
	});
}

Multiple simultaneous locks

const mutexAsync = require('mutex-async');

const mutex = new mutexAsync.Mutex({
	maxLocks: 10
});

async function criticalSection() {
	let unlock = await mutex.lock();
	try {
		await new Promise(resolve => setTimeout(resolve, 1000));
	} catch(err) {}
	await unlock();
}

// will only take 2 seconds
let promises = [];
for(let i = 0; i < 20; i++) {
	promises.push(criticalSection());
}
await Promise.all(promises);

Functions

  • mutex.lock() - returns a promise that resolves to a function that will unlock the mutex when the mutex is available
  • mutex.run(fn) - runs the function fn when the mutex is available, returns a promise that resolves to the return value of fn
  • mutex.isLocked() - returns true if the mutex is currently locked and the next lock will wait, false otherwise
  • mutex.getLockCount() - returns the number of locks currently held
  • mutex.getWaitCount() - returns the number of locks waiting to be resolved.
  • mutex.unlock() - unlocks the mutex, if there are any waiting locks, the next one will be resolved immediately. use the unlock function returned by lock() instead for better protection against double unlocks.

Options

These options are configured by passing in an object with them into the constructor. Also they can also be changed at any time by assigning a new value to the property of the same name on the mutex instance.

  • maxLocks - the maximum number of locks that can be held at the same time, default is 1.
  • warnOnOverlap - if true, will log a warning whenever a lock needs to wait for another to complete. default is false.

License

MIT License