Last active
December 18, 2015 07:09
-
-
Save jonnyreeves/5744277 to your computer and use it in GitHub Desktop.
Message Passing
This file contains hidden or 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
// Register a message handler for "some message" | |
messageBus.addHandler("some_message", function (message, next) { | |
// do something with the data in an async fashion | |
$.get(message.url, function () { | |
if (response.code !== 200) { | |
// Transition into an error state, terminates processing. | |
next(new Error("bad http request!")); | |
} | |
else { | |
// Modify the state of the object and pass execution to the next handler | |
message.someState = response; | |
} | |
}); | |
}); | |
// Trigger a message... | |
messageBus.dispatch("some_message", function (err, message) { | |
// Callback is invoked after all handlers have triggered. | |
// error will be null if no error was raised. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment