Skip to content

Node semaphore with protection against double-returning

Notifications You must be signed in to change notification settings

cjdelisle/saferphore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Node semaphore with protection against double-returning

Resources

Stars

Watchers

Forks

Packages

No packages published