Created
September 10, 2012 18:47
-
-
Save oscarrenalias/3692870 to your computer and use it in GitHub Desktop.
An example of an event emitter class in Node.js
This file contains hidden or 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 events = require('events'), | |
| util = require('util'); | |
| EventGenerator = function() { | |
| events.EventEmitter.call(this); | |
| this.read = function() { | |
| var data = "this is new data"; | |
| this.emit("data", data); | |
| } | |
| } | |
| util.inherits(EventGenerator, events.EventEmitter); | |
| function setup() { | |
| return(new EventGenerator()); | |
| } | |
| var generator = setup(); | |
| generator.on("data", function(data) { | |
| console.log("new data received: " + data); | |
| }) | |
| generator.read(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment