Created
December 10, 2015 04:00
-
-
Save JonathonMA/24f242828e2c15d94caa 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'); | |
var simpleBus = new events.EventEmitter(); | |
var strictlyOrderedBus = {}; | |
strictlyOrderedBus.bus = simpleBus; | |
strictlyOrderedBus.emit = function(evt) { setImmediate(this.bus.emit.bind(this.bus), evt); } | |
strictlyOrderedBus.on = simpleBus.on | |
var globalBus; | |
function func1() { | |
console.log("func1: start"); | |
globalBus.emit("event2"); | |
console.log("func1: end"); | |
} | |
function func2() { | |
console.log("func2: start"); | |
console.log("func2: end"); | |
} | |
function func3() { | |
console.log("func3: start"); | |
console.log("func3: end"); | |
} | |
globalBus = simpleBus; | |
globalBus.on("event1", func1); | |
globalBus.on("event1", func2); | |
globalBus.on("event2", func3); | |
console.log("triggering event1 on simpleBus"); | |
globalBus.emit("event1"); | |
globalBus = strictlyOrderedBus; | |
console.log("triggering event1 on strictlyOrderedBus"); | |
globalBus.emit("event1"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment