···1717 Option.iter (fun s -> log ("sharp_ppf: " ^ s)) o.sharp_ppf;
1818 Option.iter (fun s -> log ("caml_ppf: " ^ s)) o.caml_ppf
19192020-let start rpc =
2020+let _ =
2121 let ( let* ) = Lwt_result.bind in
2222+ let* rpc = initialise "worker.js" (fun _ -> log "Timeout") in
2223 let* o = W.setup rpc () in
2324 log_output o;
2424- Lwt.return (Ok o)
2525-2626-let exec rpc txt =
2727- let ( let* ) = Lwt_result.bind in
2828- let* o = W.exec rpc txt in
2525+ let* o = W.exec rpc "2*2;;" in
2926 log_output o;
3030- Lwt.return (Ok o)
3131-3232-let _ =
3333- let ( let* ) = Lwt_result.bind in
3434- let* rpc = initialise "worker.js" (fun _ -> log "Timeout") in
3535- let* _ = start rpc in
3636- let* _ = exec rpc "2*2;;" in
3727 Lwt.return (Ok ())
+10
idl/js_top_worker_client.ml
···6161module Wraw = Toplevel_api_gen.Make (Rpc_lwt.GenClient ())
62626363module W : sig
6464+ type init_libs = Toplevel_api_gen.init_libs
6565+ type err = Toplevel_api_gen.err
6666+ type exec_result = Toplevel_api_gen.exec_result
6767+ type completion_result = Toplevel_api_gen.completion_result
6868+6469 val init :
6570 rpc ->
6671 Toplevel_api_gen.init_libs ->
···8186 string ->
8287 (Toplevel_api_gen.completion_result, Toplevel_api_gen.err) result Lwt.t
8388end = struct
8989+ type init_libs = Toplevel_api_gen.init_libs
9090+ type err = Toplevel_api_gen.err
9191+ type exec_result = Toplevel_api_gen.exec_result
9292+ type completion_result = Toplevel_api_gen.completion_result
9393+8494 let init rpc a = Wraw.init rpc a |> Rpc_lwt.T.get
8595 let setup rpc a = Wraw.setup rpc a |> Rpc_lwt.T.get
8696 let exec rpc a = Wraw.exec rpc a |> Rpc_lwt.T.get
+35-17
idl/js_top_worker_client.mli
···99 this exception. *)
10101111type rpc = Rpc.call -> Rpc.response Lwt.t
1212+(** RPC function for communicating with the worker. This is used by each
1313+ RPC function declared in {!W} *)
12141315val start : string -> int -> (unit -> unit) -> rpc
1416(** [start url timeout timeout_fn] initialises a web worker from [url] and
1517 starts communications with it. [timeout] is the number of seconds to wait
1618 for a response from any RPC before raising an error, and [timeout_fn] is
1717- called when a timeout occurs. *)
1919+ called when a timeout occurs. Returns the {!type-rpc} function used
2020+ in the RPC calls. *)
18211922module W : sig
2020- val init :
2121- rpc ->
2222- Toplevel_api_gen.init_libs ->
2323- (unit, Toplevel_api_gen.err) result Lwt.t
2323+ (** {2 Type declarations}
2424+2525+ The following types are redeclared here for convenience. *)
24262525- val setup :
2626- rpc ->
2727- unit ->
2828- (Toplevel_api_gen.exec_result, Toplevel_api_gen.err) result Lwt.t
2727+ type init_libs = Toplevel_api_gen.init_libs
2828+ type err = Toplevel_api_gen.err
2929+ type exec_result = Toplevel_api_gen.exec_result
3030+ type completion_result = Toplevel_api_gen.completion_result
29313030- val exec :
3131- rpc ->
3232- string ->
3333- (Toplevel_api_gen.exec_result, Toplevel_api_gen.err) result Lwt.t
3232+ (** {2 RPC calls}
3333+3434+ The first parameter of these calls is the rpc function returned by
3535+ {!val-start}. If any of these calls fails to receive a response from
3636+ the worker by the timeout set in the {!val-start} call, the {!Lwt}
3737+ thread will be {{!Lwt.fail}failed}.
3838+ *)
34393535- val complete :
3636- rpc ->
3737- string ->
3838- (Toplevel_api_gen.completion_result, Toplevel_api_gen.err) result Lwt.t
4040+ val init : rpc -> init_libs -> (unit, err) result Lwt.t
4141+ (** Initialise the toplevel. This must be called before any other API. *)
4242+4343+ val setup : rpc -> unit -> (exec_result, err) result Lwt.t
4444+ (** Start the toplevel. Return value is the initial blurb
4545+ printed when starting a toplevel. Note that the toplevel
4646+ must be initialised first. *)
4747+4848+ val exec : rpc -> string -> (exec_result, err) result Lwt.t
4949+ (** Execute a phrase using the toplevel. The toplevel must have been
5050+ Initialised first. *)
5151+5252+ val complete : rpc -> string -> (completion_result, err) result Lwt.t
5353+ (** Find completions of the incomplete phrase. Completion occurs at the
5454+ end of the phrase passed in. If completion is required at a point
5555+ other than the end of a string, then take the substring before calling
5656+ this API. *)
3957end
+1-1
idl/toplevel_api.ml
···77777878 let init =
7979 declare "init"
8080- [ "Initialise the toplevel." ]
8080+ [ "Initialise the toplevel. This must be called before any other API." ]
8181 (init_libs @-> returning unit_p err)
82828383 let setup =