1.0.4 • Published 4 years ago

named-mutex v1.0.4

Weekly downloads
11
License
MIT
Repository
github
Last release
4 years ago

named-mutex-js

cross process named mutex

Install

>npm install --save named-mutex

Usage

child.js

const NamedMutex = require('named-mutex')

const mutex = new NamedMutex('testMutex')
console.log(mutex.tryLock())

setTimeout(()=>{
  console.log('process leaving')
}, 3000)

main.js

const NamedMutex = require('../src/named-mutex')
const cp = require('child_process')

const mutex = new NamedMutex('testMutex')
console.log(mutex.tryLock()) // output: true
const {stdout} = cp.spawnSync('node', ['child.js'])
console.log(stdout.toString().trim()) // output: false
mutex.unLock() // process still release the mutex on leave, even if this line is absent
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago