Created
November 24, 2012 12:12
-
-
Save seriousManual/4139428 to your computer and use it in GitHub Desktop.
emitted events are not acting asynchronous
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
var EE = require( 'events').EventEmitter; | |
var utils = require( 'util' ); | |
function MyEmitter() { | |
EE.call( this ); | |
var that = this; | |
this.doit = function() { | |
//doing something..... | |
that.emit( 'done' ); | |
} | |
} | |
utils.inherits( MyEmitter, EE ); | |
var a = new MyEmitter(); | |
a.on( 'done', function() { | |
console.log( 'hes done it!' ); | |
} ); | |
console.log( 'wait for it....' ); | |
a.doit(); | |
console.log( '...legendary!' ); | |
/* | |
OUTPUT: | |
wait for it.... | |
hes done it! | |
....legendary! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment