Caleb James DeLisle 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
..
.flowconfig 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
.jshintignore 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
.jshintrc 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
.travis.yml 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
index.js 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
package.json 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
readme.md 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă
test.js 6a29c552ab Separation of concerns between builder and cjdns-specific build stuff 4 ani în urmă

readme.md

Saferphore - Node semaphore with protection against double-returning

# node
npm install --save saferphore

# Browser
bower install --save saferphore
const Saferphore = require('saferphore');

var sem = Saferphore.create(4);
for (var i = 0; i < 10000; i++) {
    sem.take(function (returnAfter) {
        Fs.writeFile('file_' + i, 'hi', returnAfter(function (err) {
            if (err) { throw err; }
        });
    });
}

You can only return what you take, if you try to call returnAfter() twice then it will throw a clear error instead of creating a leaky semaphore.

sem.take(function (returnAfter) {
    stream.on('data', returnAfter(processData)); // BZZZZZZZT error when it's called more than once
});