Promise based mutex

Usage no npm install needed!

<script type="module">
  import cfwarePMutex from 'https://cdn.skypack.dev/@cfware/p-mutex';



Travis CI Greenkeeper badge NPM Version NPM Downloads MIT

Promise based mutex

Install @cfware/p-mutex

This module requires node.js 13.2.0 or above.

npm i --save @cfware/p-mutex


import {PMutex} from '@cfware/p-mutex';

/* PMutex ignores any parameters. */
const mutex = new PMutex();

export const serializedAsyncAction = async () => {
    const lock = await mutex.lock();

    /* Do some stuff, release the lock eventually. */
    setTimeout(() => lock.release(), 10);

This module does not provide timeout functionality. lock.release() must be called or the mutex.lock() will never resolve again.