mutexor

0.1.0 • Public • Published

Mutexor

install

npm install --save mutexor

how to use it

const Mutex = require('mutexor');
const fs = require('fs');

let mutex = Mutex();

for (let i = 0; i < 10000; i++) {
    mutex.lock(function (unlock) {
        // called when mutex is locked
        fs.writeFile('myFile', `myData${i}`, function (err) {
            console.log(i);
            unlock(); // unlock mutex
        });
    })
    .then(function () {
        // called when mutex is unlocked
    });
}

OR

const Mutex = require('mutexor');
const fs = require('fs');

let mutex = Mutex();

for (let i = 0; i < 10000; i++) {
    mutex
        .lock()
        .then(function (unlock) {
            // called when mutex is locked
            fs.writeFile('myFile', `myData${i}`, function (err) {
                console.log(i);
                unlock(); // unlock mutex
            });
        });
}

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i mutexor

    Weekly Downloads

    0

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • lseguin