https://github.com/cfware/p-mutex
Promise based mutex
https://github.com/cfware/p-mutex
Last synced: about 1 year ago
JSON representation
Promise based mutex
- Host: GitHub
- URL: https://github.com/cfware/p-mutex
- Owner: cfware
- License: mit
- Created: 2017-12-02T08:14:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-11-06T15:13:57.000Z (over 5 years ago)
- Last Synced: 2025-03-10T21:05:33.231Z (about 1 year ago)
- Language: JavaScript
- Size: 110 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @cfware/p-mutex [![NPM Version][npm-image]][npm-url]
Promise based mutex
## Usage
```js
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.
[npm-image]: https://img.shields.io/npm/v/@cfware/p-mutex.svg
[npm-url]: https://npmjs.org/package/@cfware/p-mutex