···118118 if List.length urls > 0 then failwith "Not implemented" else ()
119119120120 let init_function _ () = failwith "Not implemented"
121121- let findlib_init _ = ()
121121+ let findlib_init _ = Lwt.return ()
122122 let get_stdlib_dcs _uri = []
123123124124 let require _ () packages =
+19-8
lib/findlibish.ml
···109109 Rpcmarshal.unmarshal
110110 Js_top_worker_rpc.Toplevel_api_gen.typ_of_dynamic_cmis rpc
111111112112-let init sync_get findlib_index : t =
112112+let (let*) = Lwt.bind
113113+114114+let init (async_get : string -> (string, [>`Msg of string]) result Lwt.t) findlib_index : t Lwt.t =
113115 Jslib.log "Initializing findlib";
116116+ let* findlib_txt = async_get findlib_index in
114117 let findlib_metas =
115115- match sync_get findlib_index with
116116- | None -> []
117117- | Some txt -> Astring.String.fields ~empty:false txt
118118+ match findlib_txt with
119119+ | Error (`Msg m) ->
120120+ Jslib.log "Error fetching findlib index: %s" m;
121121+ []
122122+ | Ok txt -> Astring.String.fields ~empty:false txt
118123 in
119119- let metas =
120120- List.filter_map
124124+ let* metas =
125125+ Lwt_list.map_p
121126 (fun x ->
122122- match sync_get x with Some meta -> Some (x, meta) | None -> None)
127127+ let* res = async_get x in
128128+ match res with
129129+ | Error (`Msg m) ->
130130+ Jslib.log "Error fetching findlib meta %s: %s" x m;
131131+ Lwt.return_none
132132+ | Ok meta -> Lwt.return_some (x, meta))
123133 findlib_metas
124134 in
135135+ let metas = List.filter_map Fun.id metas in
125136 List.filter_map
126137 (fun (x, meta) ->
127138 match Angstrom.parse_string ~consume:All Uri.Parser.uri_reference x with
···150161 Jslib.log "Failed to parse uri: %s" m;
151162 None)
152163 metas
153153- |> flatten_libs
164164+ |> flatten_libs |> Lwt.return
154165155166let require sync_get cmi_only v packages =
156167 let rec require dcss package :
+9-5
lib/impl.ml
···109109 val import_scripts : string list -> unit
110110 val init_function : string -> unit -> unit
111111 val get_stdlib_dcs : string -> Toplevel_api_gen.dynamic_cmis list
112112- val findlib_init : string -> findlib_t
112112+ val findlib_init : string -> findlib_t Lwt.t
113113 val path : string
114114115115 val require :
···120120 let functions : (unit -> unit) list option ref = ref None
121121 let requires : string list ref = ref []
122122 let path : string option ref = ref None
123123- let findlib_v : S.findlib_t option ref = ref None
123123+ let findlib_v : S.findlib_t Lwt.t option ref = ref None
124124 let execution_allowed = ref true
125125126126 let refill_lexbuf s p ppf buffer len =
···373373 path := Some S.path;
374374375375 findlib_v := Some (S.findlib_init "findlib_index");
376376+376377 let stdlib_dcs =
377378 match init_libs.stdlib_dcs with
378379 | Some dcs -> dcs
···418419 failwith ("Error: " ^ err)
419420 in
420421421421- let dcs =
422422+ let* dcs =
422423 match !findlib_v with
423423- | Some v -> S.require (not !execution_allowed) v !requires
424424- | None -> []
424424+ | Some v ->
425425+ let* v = v in
426426+ Lwt.return (S.require (not !execution_allowed) v !requires)
427427+ | None -> Lwt.return []
425428 in
429429+426430 let* () = Lwt_list.iter_p add_dynamic_cmis dcs in
427431428432 Logs.info (fun m -> m "setup() finished");
+1-1
lib/worker.ml
···5959 Findlibish.fetch_dynamic_cmis sync_get uri |> Result.to_list
60606161 let import_scripts = Js_of_ocaml.Worker.import_scripts
6262- let findlib_init = Findlibish.init sync_get
6262+ let findlib_init = Findlibish.init async_get
63636464 let require b v = function
6565 | [] -> []