Re:Async and Await
by romanovcode on Friday June 03, 2016 @04:52AM
(#11829111)
I much rather write coffeescript, but at least I can understand the code much better this way and it is not such an abomination.
I seriously don't get how people like Javascript when to do such a simple things you need so much code that looks so ugly (IMO).
[ Parent
| on HN ]
Re:Async and Await
by doublerebel on Friday June 03, 2016 @05:30AM
(#11829213)
This is how I've been writing Iced Coffeescript for years. I still believe it's a major improvement over the typical promise syntax.
And to make the error handling even cleaner, check out the errify/errorCallback pattern:
http://maxtaco.github.io/programming/2014/09/18/handling-err...
https://www.npmjs.com/package/errify
https://github.com/nextorigin/express-rendertype/blob/master...
Re:Async and Await
by romanovcode on Friday June 03, 2016 @06:01AM
(#11829304)
Hm, looks interesting. I wonder if it would be possible to monkey-patch the defer itself in something like this. So that defer itself is handling it, but only if you do the the monkey-patching per file and not globally.
defer = require 'defer-esc'
await req.get 'https://x.io', defer err, http, res # if err will call cb err
await req.get "https://x.io?hash=#{res.hash}", defer err, http, res # if err will call cb err
return cb res