Module Msgpack_rpc

Implements the Msgpack RPC protocol. See https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md

module Error : sig ... end
type t
val create : on_error:(Error.t -> unit) -> t

Create a new Msgpack RPC instance.

val connect : t -> Async.Reader.t -> Async.Writer.t -> unit

Once connect is called the counterparty can start calling methods and sending notifications. Any methods that should be callable at that time should be registered beforehand. Calling connect twice will raise.

val reader : t -> Async.Reader.t

Get the reader provided to connect. Fails if connect has not yet been called.

val writer : t -> Async.Writer.t

Get the writer provided to connect. Fails if connect has not yet been called.

val call : t -> method_name:string -> parameters:Msgpack.t list -> (Msgpack.t, Msgpack.t) Core.Result.t Async_kernel.Deferred.Or_error.t
val notify : t -> method_name:string -> parameters:Msgpack.t list -> unit Async_kernel.Deferred.Or_error.t
val register_request_handler : t -> name:string -> f: (Msgpack.t list -> (Msgpack.t Core.Or_error.t * 'a) Async_kernel.Deferred.t) -> on_response_sent:('a -> unit) -> [ `Ok | `Duplicate ]

Register a handler that will be called when a request (message type 0) for method name is received. on_response_sent is called after the response has been written and the writer is flushed (if you don't need this hook, just pass ignore).

Although you can still register handlers after the RPC is connected, note that if clients call the method before registration they will receive an error response for an undefined method.

val register_notification_handler : t -> name:string -> f:(Msgpack.t list -> unit) -> [ `Ok | `Duplicate ]

Register a handler that will be called when a notification (message type 2) for method name is received.

Although you can still register handlers after the RPC is connected, note that if clients call the method before registration the default notification handler will be invoked.

val set_default_notification_handler : t -> f:(name:string -> Msgpack.t list -> unit) -> unit

Set the default notification handler to be invoked when a notification is received for a method for which no handler is registered. We don't need a default request handler because we can just return an error response when a request for an unknown method is received, but notifications do not have responses so we need to define a behavior for this scenario explicitly. By default these notifications will be ignored.

module Expert : sig ... end