| > Up until recently that was pretty much all we had. [Edit: see my comment below[0]. This is more a coincidence of wording than a StrongLoop marketing line] When StrongLoop talked at my south bay node.js meetup group, BayNode[1], at Hacker Dojo last month, they demoed Zone.js. Before demoing though, they asked if anyone in the group had "solved this" to which I made it very clear that, "Yes, I did about 2 years ago with trycatch[2]." Their response could be summed up as, "Oh?" Long story short, not only does my async try/catch library solve this, I can say with near certainty that it solves it in a better, more consistent, more tested, more battle proven, more performant manner. We use trycatch at LinkedIn and have not had to worry about async error handling since. Additionally, adding it to any control-flow of your choice is trivial, as I have done with my stepup library[3]. Further, their main bullet-points are about enforcing the callback contract, something EVERY control-flow library should be doing, (I previously went into more detail here[4]) and the primary reason for the popularity of promises since they formalized this contract. In fact, I teach these core contract rules in my monthly week-long node.js bootcamp I give here at LinkedIn[5], and the only thing they have to do with control-flow is that your control-flow library of choice should enforce them, as stepup and promises do. I do add a few rules: * Function that takes 2 arguments: 1. first argument is an error, 2. second argument is the result, 3. Never pass both, 4. error should be instanceof Error * Must never excecute on the same tick of the event loop * Must be passed as last argument to function * Return value is ignored * Must not throw / must pass resulting errors * Must never be called more than once Long story short, domains are broken, try/catch is insufficient, use trycatch because I solved this problem over 2 years ago and have been perfecting it since. [0] https://news.ycombinator.com/item?id=7598983 [1] http://www.meetup.com/BayNode/ [2] https://github.com/CrabDude/trycatch [3] https://github.com/CrabDude/stepup [4] https://news.ycombinator.com/item?id=7020054 [5] https://gist.github.com/CrabDude/10907185 |
Then the key part in Dart is that all of the APIs that invoke callbacks based on external events run the callbacks in the Zone they were registered in. This is what allows Zones to be used to easily run code at the beginning or end of every event loop turn.