Skip to content

Instantly share code, notes, and snippets.

@maxov maxov/once.js
Created Jun 10, 2014

Embed
What would you like to do?
function that makes a function that only calls once
// do cb only once
function do_once(cb) {
var has_called = false;
// the function that is returned
return function () {
if(!has_called) {
cb.apply(arguments);
has_called = true;
}
}
}
// usage example
process.once('SIGINT', do_once(function (conn) { conn.close(); }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.