Created
December 3, 2013 05:41
-
-
Save AWinterman/7764423 to your computer and use it in GitHub Desktop.
Asynchronous + event emitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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