Module Js_top_worker_client_msgSource
Worker client using the message protocol.
This client communicates with the OCaml toplevel worker using a simple JSON message protocol instead of RPC.
module Brr_worker = Brr_webworkers.Workermodule Brr_message = Brr_io.Messagetype output_at = {cell_id : int;loc : int;(*Character position after phrase (pos_cnum)
*)caml_ppf : string;mime_vals : Msg.mime_val list;
}Incremental output from a single phrase
type output = {cell_id : int;stdout : string;stderr : string;caml_ppf : string;mime_vals : Msg.mime_val list;
}Output result type
type eval_event = | Phrase of Js_top_worker_client_msg.output_at(*Incremental output after each phrase
*)| Done of Js_top_worker_client_msg.output(*Final result
*)| Error of string(*Error occurred
*)
Eval stream event
type t = {worker : Brr_worker.t;timeout : int;mutable cell_id : int;mutable ready : bool;ready_waiters : (unit -> unit) Stdlib.Queue.t;pending : (int, Msg.worker_msg Lwt.u) Stdlib.Hashtbl.t;pending_env : (string, Msg.worker_msg Lwt.u) Stdlib.Hashtbl.t;pending_stream : (int, Js_top_worker_client_msg.eval_event option -> unit) Stdlib.Hashtbl.t;mutable on_widget_update : (string -> Js_of_ocaml.Js.Unsafe.any -> unit) option;mutable on_widget_clear : (string -> unit) option;mutable on_widget_config : (string -> string -> unit) option;mutable on_widget_command : (string -> string -> string -> unit) option;mutable on_widget_register_adapter : (string -> string -> unit) option;
}Client state
Use plain JSON.stringify/JSON.parse for cross-jsoo-version compatibility.
Parse a worker message from JSON string
Handle incoming message from worker
Create a new worker client.
Get next cell ID
val send :
Js_top_worker_client_msg.t ->
[< `Complete of 'a * string * string * 'b * string option
| `CreateEnv of string
| `DestroyEnv of string
| `Errors of 'c * string * string * string option
| `Eval of 'd * string * string
| `Init of Msg.init_config
| `TypeAt of 'e * string * string * 'f * string option ] ->
unitSend a message to the worker
Wait for the worker to be ready
Initialize the worker
val eval :
Js_top_worker_client_msg.t ->
?env_id:string ->
string ->
Js_top_worker_client_msg.output Lwt.tEvaluate OCaml code
val eval_stream :
Js_top_worker_client_msg.t ->
?env_id:string ->
string ->
Js_top_worker_client_msg.eval_event Lwt_stream.tEvaluate OCaml code with streaming output. Returns a stream of events: Phrase for each phrase as it executes, then Done with the final result, or Error if evaluation fails.
val complete :
Js_top_worker_client_msg.t ->
?filename:string ->
?env_id:string ->
string ->
'a ->
Msg.completions Lwt.tGet completions
val type_at :
Js_top_worker_client_msg.t ->
?filename:string ->
?env_id:string ->
string ->
'a ->
Msg.type_info list Lwt.tGet type at position
val errors :
Js_top_worker_client_msg.t ->
?filename:string ->
?env_id:string ->
string ->
Msg.error list Lwt.tGet errors
Create environment
Destroy environment
val set_on_widget_update :
Js_top_worker_client_msg.t ->
(string -> Js_of_ocaml.Js.Unsafe.any -> unit) ->
unitSet callback for widget update messages. The callback receives (widget_id, raw_view_json) where raw_view_json is the unparsed JS object for the view node.
Set callback for widget clear messages.
Set callback for widget config messages.
val set_on_widget_command :
Js_top_worker_client_msg.t ->
(string -> string -> string -> unit) ->
unitSet callback for widget command messages.
val set_on_widget_register_adapter :
Js_top_worker_client_msg.t ->
(string -> string -> unit) ->
unitSet callback for widget adapter registration messages.
val send_widget_event :
Js_top_worker_client_msg.t ->
widget_id:string ->
handler_id:string ->
event_type:string ->
value:string option ->
unitSend a widget event back to the worker.
Terminate the worker