Skip to content

Instantly share code, notes, and snippets.

@ithinkihaveacat
Created February 3, 2010 18:20
Show Gist options
  • Save ithinkihaveacat/293847 to your computer and use it in GitHub Desktop.
Save ithinkihaveacat/293847 to your computer and use it in GitHub Desktop.
var events = require('events'), sys = require('sys');
var emitter = new events.EventEmitter();
function fn1() {
sys.debug("in fn1");
emitter.addListener("foo", fn2);
process.nextTick(function() {
emitter.removeListener("foo", fn1);
});
}
function fn2() {
sys.debug("in fn2");
process.nextTick(function() {
emitter.removeListener("foo", fn2);
});
}
emitter.addListener("foo", fn1);
emitter.emit("foo");
emitter.emit("foo");
// outputs fn1, fn2, fn1, fn2, fn2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment