paren6
paren6 copied to clipboard
async/await?
Hello,
How can we write async/await functions with Parenscript? The expected result is
async function foo(){
await bar();
}
It would be a good fit for paren6, right? If so, do you have an idea how to add it? I just skimmed through ps macros.
Thanks
I imagine it would be a good fit. I'll have a look at it.
Okay, here's the homework so far...
It should be pretty simple to reuse the code from es5-async-await except that it needs Promise and fibers/future.
At the moment, there is no good system for requesting dependencies for a parenscript library. So until I or some other volunteer comes up with such a system, we're left with telling the user to manually require them. Awkward but possible.
There are some babel plugins from which technique could be borrowed: regenerator implements generators for ES5. Fast-async manages to implement async/await entirely with promises.
My babel-plugin-fu is not strong. I'm not sure how easy it would be to translate either of these approaches into parenscript. Nor is it evident that they can be implemented without dependencies.
Vindarel, are you interested in implementing this? Personally, I have mixed feelings. It would be fun, but also might involve more homework than I want to take on ATM.
uhoh. I'm surprised by the mention of es5-async-await, babel and all. I was thinking that we'd need to define one or two Parenscript macros, so we could write something like:
(ps:ps
(ps:defasync foo ()
(ps:await (bar)))
which would be turned to the JS above.
Guys, it would be cool to implement async/await
. @vindarel did you find some workaround?