paren6 icon indicating copy to clipboard operation
paren6 copied to clipboard

async/await?

Open vindarel opened this issue 5 years ago • 4 comments

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

vindarel avatar Dec 23 '19 18:12 vindarel

I imagine it would be a good fit. I'll have a look at it.

BnMcGn avatar Dec 24 '19 14:12 BnMcGn

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.

BnMcGn avatar Dec 27 '19 14:12 BnMcGn

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.

vindarel avatar Jan 03 '20 19:01 vindarel

Guys, it would be cool to implement async/await. @vindarel did you find some workaround?

svetlyak40wt avatar Jun 25 '23 21:06 svetlyak40wt