In other words, the following asynchronous code:
var d = Domain.create()
d.on("error", function (error) {
console.error("Error with the twitterverse:", error)
})
d.enter()
getTweetsFor("domenic")
.reduce(findMostMentioned, [])
.map(function (mostMentioned) {
return mostMentioned.map(function (user) { return user.username })
})
.toArray(function (mostMentionedNames) {
console.log("Most mentioned names:", mostMentionedNames)
})
d.exit()
parallels the synchronous code:
try {
var mostMentioned = findMostMentioned(getTweetsFor("domenic"))
var mostMentionedNames = mostMentioned.map(function (user) { return user.username })
console.log("Most mentioned names:", mostMentionedNames)
} catch (error) {
console.error("Error with the twitterverse: ", error)
}
Note in particular how errors flowed from any step in the process to our catch handler, without explicit by-hand bubbling code.
I still maintain that you have a hammer and all you see are nails. (In this analogy, promises are a screwdriver. Both can useful for building things but nailing screws into the wall is ignoring the benefits of having them securely screwed.)