Skip to content

Instantly share code, notes, and snippets.

@maxov
Created June 10, 2014 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxov/d3c12e5ef62d2046404d to your computer and use it in GitHub Desktop.
Save maxov/d3c12e5ef62d2046404d to your computer and use it in GitHub Desktop.
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