Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mtripg6666tdr/async-lock

Promise based simple mutex for JS: preventing from running same code block at the same time.
https://github.com/mtripg6666tdr/async-lock

async async-lock browser javascript lock mutex nodejs promise promise-lock

Last synced: 10 days ago
JSON representation

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

Awesome Lists containing this project

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
```js
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](test/index.js).

## License
[MIT](LICENSE)