https://github.com/metrue/jutex
Mutex in JavaScript
https://github.com/metrue/jutex
Last synced: 2 months ago
JSON representation
Mutex in JavaScript
- Host: GitHub
- URL: https://github.com/metrue/jutex
- Owner: metrue
- Created: 2020-01-16T10:41:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-17T05:29:55.000Z (over 5 years ago)
- Last Synced: 2025-01-11T02:29:18.804Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mutex
A mutex implementation in Node/JavaScript
## Usage
* function
```javascript
const mutex = new Mutex()let mark1 = false
let mark2 = falseconst fn1 = () => {
setTimeout(() => {
mark1 = true
}, 1000)
}
const fn2 = () => {
setTimeout(() => {
mark2 = true
}, 1500)
}mutex.aquire(fn1)
mutex.aquire(fn2)```
* async function (Promise)
```javascript
const mutex = new Mutex()let mark1 = false
let mark2 = falseconst fn1 = async () => new Promise(res => {
setTimeout(() => {
mark1 = true
res(true)
}, 1000)
})
const fn2 = async () => new Promise(res => {
setTimeout(() => {
mark2 = true
res(true)
}, 1500)
})mutex.aquire(fn1)
mutex.aquire(fn2)
```