mutex-node
v1.0.0
Published
mutex object for large node applications with complex state and state update coroutines
Downloads
18
Readme
node-mutex
mutex object for large node applications with complex state and state update coroutines
How to use
const {createMutex, wait} = require('node-mutex');
const func1(signal, ...args) = () => {
// async/await or sync code here
// calls signal at the end of execution
signal();
}
const func2(signal, ...args) = () => {
// async/await or sync code here
// calls signal at the end of execution
signal();
}
// the following code ensures func2 does not access
// the critical section (the resource it protects)
// while func1 is mid-execution
const mutex = createMutex();
wait(mutex, func1, ...args1);
wait(mutex, func2, ...args2);