minoki / LunarML

The Standard ML compiler that produces Lua/JavaScript
MIT License
356 stars 10 forks source link

Question regarding sync/await (js) #6

Open bentxt opened 1 year ago

bentxt commented 1 year ago

Hi, I just wanted to ask if javascript sync/await syntax is something you might add someday. Thanks Ben

minoki commented 1 year ago

It would be a good addition.

Since JS-CPS backend provides delimited continuations, no new syntax needs to be added. Instead, some library functions like this will do:

type 'a promise
val asyncFunction : (JavaScript.value vector -> JavaScript.value) -> JavaScript.value
(* or val async : ('a -> 'b) -> 'a -> 'b promise *)
val await : 'a promise -> 'a
val createPromise : ({ resolve : 'a -> unit, reject : exn -> unit } -> unit) -> 'a promise