jon.recoil.org

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.Worker
module Brr_message = Brr_io.Message
Sourcetype output_at = {
  1. cell_id : int;
  2. loc : int;
    (*

    Character position after phrase (pos_cnum)

    *)
  3. caml_ppf : string;
  4. mime_vals : Msg.mime_val list;
}

Incremental output from a single phrase

Sourcetype output = {
  1. cell_id : int;
  2. stdout : string;
  3. stderr : string;
  4. caml_ppf : string;
  5. mime_vals : Msg.mime_val list;
}

Output result type

Sourcetype eval_event =
  1. | Phrase of Js_top_worker_client_msg.output_at
    (*

    Incremental output after each phrase

    *)
  2. | Done of Js_top_worker_client_msg.output
    (*

    Final result

    *)
  3. | Error of string
    (*

    Error occurred

    *)

Eval stream event

Sourcetype t = {
  1. worker : Brr_worker.t;
  2. timeout : int;
  3. mutable cell_id : int;
  4. mutable ready : bool;
  5. ready_waiters : (unit -> unit) Stdlib.Queue.t;
  6. pending : (int, Msg.worker_msg Lwt.u) Stdlib.Hashtbl.t;
  7. pending_env : (string, Msg.worker_msg Lwt.u) Stdlib.Hashtbl.t;
  8. pending_stream : (int, Js_top_worker_client_msg.eval_event option -> unit) Stdlib.Hashtbl.t;
  9. mutable on_widget_update : (string -> Js_of_ocaml.Js.Unsafe.any -> unit) option;
  10. mutable on_widget_clear : (string -> unit) option;
  11. mutable on_widget_config : (string -> string -> unit) option;
  12. mutable on_widget_command : (string -> string -> string -> unit) option;
  13. mutable on_widget_register_adapter : (string -> string -> unit) option;
}

Client state

Sourceexception Timeout
Sourceexception InitError of string
Sourceexception EvalError of string
Sourceval json_global : 'a Js_of_ocaml.Js.t

Use plain JSON.stringify/JSON.parse for cross-jsoo-version compatibility.

Sourceval plain_stringify : 't1 -> 'res
Sourceval parse_worker_msg : string -> Msg.worker_msg

Parse a worker message from JSON string

Handle incoming message from worker

Sourceval create : ?timeout:int -> string -> Js_top_worker_client_msg.t

Create a new worker client.

  • parameter timeout

    Timeout in milliseconds (default: 30000)

Sourceval next_cell_id : Js_top_worker_client_msg.t -> int

Get next cell ID

Sourceval 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 ] -> unit

Send a message to the worker

Sourceval wait_ready : Js_top_worker_client_msg.t -> unit Lwt.t

Wait for the worker to be ready

Initialize the worker

Evaluate OCaml code

Evaluate 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.

Sourceval complete : Js_top_worker_client_msg.t -> ?filename:string -> ?env_id:string -> string -> 'a -> Msg.completions Lwt.t

Get completions

Sourceval type_at : Js_top_worker_client_msg.t -> ?filename:string -> ?env_id:string -> string -> 'a -> Msg.type_info list Lwt.t

Get type at position

Sourceval errors : Js_top_worker_client_msg.t -> ?filename:string -> ?env_id:string -> string -> Msg.error list Lwt.t

Get errors

Sourceval create_env : Js_top_worker_client_msg.t -> string -> unit Lwt.t

Create environment

Sourceval destroy_env : Js_top_worker_client_msg.t -> string -> unit Lwt.t

Destroy environment

Sourceval set_on_widget_update : Js_top_worker_client_msg.t -> (string -> Js_of_ocaml.Js.Unsafe.any -> unit) -> unit

Set 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.

Sourceval set_on_widget_clear : Js_top_worker_client_msg.t -> (string -> unit) -> unit

Set callback for widget clear messages.

Sourceval set_on_widget_config : Js_top_worker_client_msg.t -> (string -> string -> unit) -> unit

Set callback for widget config messages.

Sourceval set_on_widget_command : Js_top_worker_client_msg.t -> (string -> string -> string -> unit) -> unit

Set callback for widget command messages.

Sourceval set_on_widget_register_adapter : Js_top_worker_client_msg.t -> (string -> string -> unit) -> unit

Set callback for widget adapter registration messages.

Sourceval send_widget_event : Js_top_worker_client_msg.t -> widget_id:string -> handler_id:string -> event_type:string -> value:string option -> unit

Send a widget event back to the worker.

Sourceval terminate : Js_top_worker_client_msg.t -> unit

Terminate the worker