3 ms·
Can't you use promises/deferreds instead?
by timepiece 12y ago
Can't you use promises/deferreds instead?
- barosl 12y agoI do think promise and deferred are huge improvements to ergonomics, but still... I cannot completely love the code bloat (which is much smaller and easier to reason about than callback hell, of course) that is caused by those libraries. I much prefer Haskell's monadic interface or Python's `yield from`. But that may be my personal preference.
- timepiece 12y agoGrownups in charge of the lang are listening and they're doing their best to incorporate these features (async/yield) in the language as soon as possible. Don't despair the future is bright :)
- ufo 12y agoOne thing yield/await does is that if plays nice with existing control-flow mechanisms in the language. You can put them inside a for loop, if statement, try-catch block, etc. With promises all of those have to be reimplemented in a library and all your code needs to be converted to the "promisified" version of things. The different syntax also prevents you from creating functions that can be reused by both sync and async code. The big thing promises and other callback-based control flow libraries do is that they fix exception handling in async code (its a PITA to add error handlers in every callback when writing async code by hand). They also let you avoid some of the awkward "pyramid of doom" nesting but thats not really killer feature because you can also achieve that by using tons of named functions.
- tracker1 12y agoasync/await are coming with ES7 and available today with BabelJS and other transpilers. Though not part of core, they rely on thenables/promises, which handle the reject/resolve which get composed with generators. The required bits are in place... alternatively you can use co/koa which uses generators along with yeilding promises to act in a similar fashion.. it does work pretty well, and will only get better.