Created
February 3, 2010 18:20
-
-
Save ithinkihaveacat/293847 to your computer and use it in GitHub Desktop.
This file contains 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'), 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