LunarML icon indicating copy to clipboard operation
LunarML copied to clipboard

Question regarding sync/await (js)

Open bentxt opened this issue 2 years ago • 1 comments
trafficstars

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

bentxt avatar Jun 08 '23 16:06 bentxt

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

minoki avatar Jun 13 '23 09:06 minoki