Skip to content

Instantly share code, notes, and snippets.

@AWinterman
Created December 3, 2013 05:41
Show Gist options
  • Save AWinterman/7764423 to your computer and use it in GitHub Desktop.
Save AWinterman/7764423 to your computer and use it in GitHub Desktop.
Asynchronous + event emitter
E = require('events').EventEmitter
function fn(ready, eventArg) {
var result = // do some async stuff with to compute result
if(/* error encountered */) {
ready(new Error)
}
ready(null, result)
}
function onready(err, result) {
// whatever you need when async operation is finished
}
E.on('event', fn.bind(fn, onready)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment