Skip to content

Instantly share code, notes, and snippets.

@richardscarrott
Created February 18, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardscarrott/29d45ca7a220449b9086 to your computer and use it in GitHub Desktop.
Save richardscarrott/29d45ca7a220449b9086 to your computer and use it in GitHub Desktop.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
function handler1() {
console.log('first handler');
myEmitter.removeListener('event', handler2);
}
function handler2() {
console.log('second handler');
}
myEmitter.on('event', handler1);
myEmitter.on('event', handler2);
myEmitter.emit('event');
myEmitter.emit('event');
// EXPECTED
// first handler
// first handler
// ACTUAL
// first handler
// second handler
// first handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment