Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@mtripg6666tdr/async-lock

mtripg6666tdr212MIT1.1.0TypeScript support: included

Promise based mutex for JS: preventing from running same code block at the same time

async-lock, promise-lock, lock, mutex

readme

async-lock

Promise based simple mutex for JS: preventing from running same code block at the same time.

API

  • LockObj (class)
    used to store mutex statuses.
  • lock (function)
    used to lock statement, just like C# lock{}.

Usage

const { lock, LockObj } = require("@mtripg6666tdr/async-lock");

const locker = new LockObj();
const someFunction = async () => {
  return await lock(locker, () => {
    // do some stuff.
  });
};

Example

Please see test file.

License

MIT