0.1.0 • Published 8 years ago

mutexor v0.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

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
            });
        });
}