Skip to content

Instantly share code, notes, and snippets.



Created Jun 10, 2014
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) {
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