Re:Show HN: Kneden – Transpile ES7 Async/await to ES6 Promis...
by callahad on Saturday February 13, 2016 @09:43AM
(#11094083)
If your target environment has promises and generators available, I'm fond of using Babel's first-party `transform-async-to-generator` plugin, which barely alters your code's syntax: https://babeljs.io/docs/plugins/transform-async-to-generator...
[ Parent
| on HN ]
Re:Show HN: Kneden – Transpile ES7 Async/await to ES6 Promis...
by marten-de-vries on Saturday February 13, 2016 @09:56AM
(#11094140)
Author of Kneden here. If generators are avaiable, you should probably indeed be using this.
If they are not though, Kneden will generate code that's probably more readable and smaller (no polyfill except for a Promise implementation).
Re:Show HN: Kneden – Transpile ES7 Async/await to ES6 Promis...
by Eridrus on Saturday February 13, 2016 @12:29PM
(#11094781)
Have you run any sorts of performance benchmarks on this?
I like async/await a lot, but I'm concerned at how much all of this JS machinery costs in terms of perf, especially compared to writing callback chains.
Re:Show HN: Kneden – Transpile ES7 Async/await to ES6 Promis...
by marten-de-vries on Saturday February 13, 2016 @12:37PM
(#11094822)
I haven't. It probably mostly depends on the JS engine and Promise implementation.
That said, it might be a good idea to hand-optimize that single hot loop, typing the Promise chain out yourself, or even using callbacks directly. It's impossible to beat that using an automated solution like this.
Re:Show HN: Kneden – Transpile ES7 Async/await to ES6 Promis...
by david-given on Saturday February 13, 2016 @10:03AM
(#11094169)
Is Babel's generator transpiling support good enough to allow this to be transpiled down to ES5?
Re:Show HN: Kneden – Transpile ES7 Async/await to ES6 Promis...
by skrebbel on Saturday February 13, 2016 @10:32AM
(#11094288)
It's actually how babel's "standard" async/await support works. First to generators, then generators to ES5-compatible code using Facebook's Regenerator (which includes a polyfill).
Pragmatic and it works, but the code isn't pretty. Which is why Kneden was made.
Re:Show HN: Kneden – Transpile ES7 Async/await to ES6 Promis...
by marten-de-vries on Saturday February 13, 2016 @10:11AM
(#11094199)
It is, the resulting code is just a bit harder to read, and the babel-polyfill is required. It's quite good considering they're transpiling generators actually, but it's hard to beat something working on a higher level (async/await straight to promises, like Kneden does.)