[ANN] Async/await is coming to ReScript!

To get a transparent support of Js.Promise.t<result<...>> and other arbitrary monadic types we would have to loose native async / await output. I think it’s a very good decision to make it work exactly as in JavaScript.

A “do” notation probably can be considered later as a separate feature. To me personally it would be a “fun to have”, while the lack of async / await is a limitation that I feel day to day when working with asynchronous code.

7 Likes

Do you spend a lot of time in your generated javascript?
We’re stuck with it without sourcemaps i guess, but otherwise, I’m particularly not interested in which syntax my generated code uses. // Generated by ReScript, PLEASE EDIT WITH CARE.

1 Like

I tend to be in generated JS often whenever I’ve tried to introduce rescript to any team. But that’s to validate that my bindings are correct, as well as show how easy it is to remove rescript if it doesn’t pan out.

One of the largest impediments has been no async await. So this is a big win!

6 Likes

:star_struck: those kind of feature will boost rescript adoption !

6 Likes

Nice work! Very excited for waiting to use it.

1 Like

Here’s a proof of concept demo of how exception analysis could play with async/await

ezgif.com-gif-maker

20 Likes

Woah that’s sweet. I can’t recall at all if Typescript has an option to enforce exception checks, or if it’s even possible, especially knowing that OCaml 5 hasn’t even implemented it.

TBH the @async and @await decorators are pretty charming. I say release them as is!

5 Likes

Can this behaviour be disabled? For example when I want to panic, I don’t care what type of exception can be thrown. And when it’s an error flow, I think it’s better to use Result.t

You can use Result. There’s nothing to disable.

2 Likes

I just finished the implementation of Async/await syntax here: https://github.com/rescript-lang/syntax/pull/600

let greetUser = async (userId) => {
  let name = await getUserName(userId)  
  "Hello " ++ name ++ "!"
}

The future is here.

21 Likes

Or rather the promise is awaiting

10 Likes

It’s times like this when I wish discourse had emoji reactions :joy:

Looking forward to trying this out! It’s a massive pain point for developers coming from modern browser development where promises are so common.

1 Like

Absolutely fantastic job @cristianoc and @Maxim :clap:t4::clap:t4::clap:t4::clap:t4: – can’t wait to try it out!

2 Likes

Wonderful! :clap: Thank you for your work @zth and @cristianoc :bowing_man:

1 Like

I cant wait! this is the only reason i didnt dive face first into rescript

2 Likes

Exciting announcement and thank you for your work!
Can’t wait to try it.

2 Likes

Update: both syntax and compiler support has been merged. Won’t make it into V10, which is just around the corner, but into the release after V10.

17 Likes

That will be V10.1 which is a big-ish step w.r.t. 10.0 in terms of functionality, but a relatively small step in terms of risk as features are already relatively well tested in there, so the 10.1 release could follow e.g. 2 or 3 months after 10.0 if no surprising issues are discovered.

13 Likes

The split between 10.0 an 10.1 is mostly about risk management, where the former contains mostly the fixes and the latter mostly the novelties, in the past year or so.

17 Likes