named-mutex

    1.0.4 • Public • Published

    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

    Install

    npm i named-mutex

    DownloadsWeekly Downloads

    2

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    5.63 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar