Nodejs removing event listeners [migrated]
- by JeffH
Looking to get some help. I'm new to Nodejs and wondering if it is possible, to remove this custom event emitter. Most of this code comes from the Hand on nodejs by Pedro Teixeira. My function at the bottom is attempting to remove the custom event emitter you setup in the book.
var util = require('util');
var EventEmitter = require('events').EventEmitter;
// Pseudo-class named ticker that will self emit every 1 second.
var Ticker = function()
{
var self = this;
setInterval(function()
{
self.emit('tick');
}, 1000);
};
// Bind the new EventEmitter to the sudo class.
util.inherits(Ticker, EventEmitter);
// call and instance of the ticker class to get the first
// event started. Then let the event emitter run the infinante loop.
var ticker = new Ticker();
ticker.on('tick', function()
{
console.log('Tick');
});
(function tock()
{
setInterval(function()
{
console.log('Tock');
EventEmitter.removeListener('Ticker',function()
{
console.log("Clocks Dead!");
});
}, 5000);
})();