Skip to content

Instantly share code, notes, and snippets.

@seriousManual
Created November 24, 2012 12:12
Show Gist options
  • Save seriousManual/4139428 to your computer and use it in GitHub Desktop.
Save seriousManual/4139428 to your computer and use it in GitHub Desktop.
emitted events are not acting asynchronous
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