https://github.com/metarhia/web-locks
Web Locks API 🔒
https://github.com/metarhia/web-locks
async atomics await data-race deadlock lock locking locks multithreading mutex nodejs parallel race-detection semaphore shared-memory sharedarraybuffer synchronization synchronize threads web-locks
Last synced: 6 months ago
JSON representation
Web Locks API 🔒
- Host: GitHub
- URL: https://github.com/metarhia/web-locks
- Owner: metarhia
- License: mit
- Created: 2020-03-06T19:42:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-01-03T21:50:42.000Z (9 months ago)
- Last Synced: 2025-04-04T05:05:48.295Z (6 months ago)
- Topics: async, atomics, await, data-race, deadlock, lock, locking, locks, multithreading, mutex, nodejs, parallel, race-detection, semaphore, shared-memory, sharedarraybuffer, synchronization, synchronize, threads, web-locks
- Language: JavaScript
- Homepage: https://metarhia.com
- Size: 203 KB
- Stars: 88
- Watchers: 11
- Forks: 11
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# Web Locks API [](https://github.com/metarhia/web-locks/actions?query=workflow%3A%22Testing+CI%22+branch%3Amaster) [](https://www.npmjs.com/package/web-locks) [](https://www.npmjs.com/package/web-locks) [](https://www.npmjs.com/package/web-locks) [](https://github.com/metarhia/web-locks/blob/master/LICENSE)
[Web Locks API](https://developer.mozilla.org/en-US/docs/Web/API/Lock)
implementation for [Node.js](https://nodejs.org/en/) based on
[`worker_threads`](https://nodejs.org/api/worker_threads.html),
[`Atomics`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics),
[`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer),
[asynchronous functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function),
and [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)).See specification: [wicg.github.io/web-locks/](https://wicg.github.io/web-locks/)
and documentation: [developer.mozilla.org/en-US/docs/Web/API/Lock](https://developer.mozilla.org/en-US/docs/Web/API/Lock)This implementation is a part of [Metarhia](https://github.com/metarhia/)
technology stack, needed for the first pilot project of Node.js application
server based on parallel programming and workload micro-isolation. Web Locks
API is intended to be merged into Node.js in future.## Features
* Simplest parallel programming primitive to solve a problem of data races and
race conditions.
* Node.js and [`worker_threads`](https://nodejs.org/api/worker_threads.html)
support.
* Different optimized implementations for certain cases: single-threaded
asynchronous locks, multi-threaded locks with a single unifyed API.## Installation
```bash
$ npm install web-locks
```## Usage
```js
await locks.request('Resource name', async lock => {
// use named resource and release it after return
});
```## License
This implementation of Web Locks API is [MIT licensed](./LICENSE).