Brr Fut.t to Jv.t, without awaiting

I am trying to use Promise.all, which creates a new promise that waits on all its args. This is what I have so far:

let _ =
  let _ocaml_promise = Brr_io.Fetch.url ~init:(Brr_io.Fetch.Request.init ()) (Jstr.v "/ocaml-url") in
  let _js_promise = Brr_io.Fetch.url ~init:(Brr_io.Fetch.Request.init ()) (Jstr.v "/js-url") in
  let _wasm_promise = Brr_io.Fetch.url ~init:(Brr_io.Fetch.Request.init ()) (Jstr.v "/wasm-url") in
  let t = Jv.Promise.all @@ Jv.of_list (fun x -> x) [ _ocaml_promise; _js_promies; _wasm_promise ] in
  Brr.Console.log [ "hello world" ]

The problem here is the (fun x → x); to use the Jv.of_list, I need sxomething which converts a Fut.t to a Jv.t . How do I do that ?

If you need to await a list of Fut.t values, I think you can use Fut.of_list ?

Note that if you want the console log to happen after the fetches you will need to await the Fut.t you get as a result:

let t = Fut.of_list [ _ocaml_promise; _js_promise; _wasm_promise ] in
Fut.await t @@ fun _responses ->
Brr.Console.log [ "hello world" ]
2 Likes