once-later

A simple wrapper around callbacks to make them fire both once and later.

Once-Later

A simple wrapper around callbacks to make them fire both once and later.

npm install once-later --save
var later = require('once-later')
 
function doSomethingAsync(callback) {
  callback = later(callback)
  
  ... later ...
  
  if (err) {
    return callback(err) // Once-Later guarantees no funky return value.
  }
  
  callback(null, ...)
}

There's a far more popular version, once, that only guarantees that the function will be called once. This combines that with the recommended practice for callback functions that all callbacks are fired later.