@mtripg6666tdr/async-lock
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

Package Sidebar

Install

npm i @mtripg6666tdr/async-lock

Weekly Downloads

93

Version

1.1.0

License

MIT

Unpacked Size

3.68 kB

Total Files

7

Last publish

Collaborators

  • mtripg6666tdr