4 ms·
Continuations can certainly be ugly (under some circumstances), and difficult, too. But there's no reason why this particular implementation of continuations ne
by ekidd 16y ago
Continuations can certainly be ugly (under some circumstances), and difficult, too. But there's no reason why this particular implementation of continuations needs to be inefficient—it has a one-to-one mapping with ordinary asynchronous JavaScript, and it generates exactly the code you'd otherwise write by hand.
Overall, I think this is a win for clarity. But I think the author should also transform functions that take a callback argument, and implicitly convert them to continuation style. Perhaps this could by adding the callback parameter automatically and transforming 'return' into a callback invocation?
async function (x) { return x; } =>
function (x, callback) { callback(x); }
- gfxmonk 16y agoRegarding transformations of returns, the initial implementation added an anonymous callback argument and converted returns into using it. But that takes the option of using the callback out of the programmer's hands, and is entirely non-obvious for someone calling the function (the number of parameters required is one more than those listed in the function definition) I plan to write a follow-up shortly that discusses possible approaches of doing this sort of thing, and your suggestion is one of the ideas I'm going to explore. Thanks for reading & commenting :)