Skip to content

Instantly share code, notes, and snippets.

@balamuru
Created February 26, 2014 17:16
Show Gist options
  • Save balamuru/9234035 to your computer and use it in GitHub Desktop.
Save balamuru/9234035 to your computer and use it in GitHub Desktop.
var fs = require('fs'); // get the fs module
var EventEmitterVar = require('events').EventEmitter, util = require('util');
var exampleEventEmitterClass= function () {
console.log("emitter constructor");
}
util.inherits(exampleEventEmitterClass, EventEmitterVar); //register class as emitter
exampleEventEmitterClass.prototype.emitMethod1 = function () {
this.emit('emittedevent1');
} ;
exampleEventEmitterClass.prototype.emitMethod2 = function () {
this.emit('emittedevent2');
} ;
//register events
var evtEmitInstance = new exampleEventEmitterClass();
evtEmitInstance
.on('emittedevent1', function () {
console.log('Executing Event Emitter 1');
})
.on('emittedevent2', function () {
console.log('Executing Event Emitter 2');
}
);
for (var i = 0; i < 3; i++) {
evtEmitInstance.emitMethod1();
}
for (var i = 0; i < 3; i++) {
evtEmitInstance.emitMethod2();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment