package babel

  1. Overview
  2. Docs
type -_ t

An a t can be used to define many rpc implementations in one go, based on a single model implementation supplied to implement_multi. The type a is usually going to be a function from the query type to the response type, including whatever deferreds, pipes, etc. that the implementation will be responsible for.

From a model implementation, define some number of rpc implementations. In practice, the result of the supplied function is usually a function, so it may be enlightening to think of the type as:

val implement_multi
  :  ?on_exception:Rpc.On_exception.t
  -> ('a -> 'b) t
  -> f:('s -> Rpc.Description.t -> 'a -> 'b)
  -> 's Rpc.Implementation.t list Or_error.t

Returns an error if any rpcs are duplicated.

val implement_multi_exn : ?on_exception:Async_rpc_kernel.Rpc.On_exception.t -> 'a t -> f:('s -> Async_rpc_kernel.Rpc.Description.t -> 'a) -> 's Async_rpc_kernel.Rpc.Implementation.t list

The protocols supported by the callee. Returns an error if any rpcs are duplicated.

val shapes_exn : _ t -> (Async_rpc_kernel.Rpc.Description.t * Shape.t) list
val supported_rpcs : _ t -> Generic_rpc.t list Core.Or_error.t
val supported_rpcs_exn : _ t -> Generic_rpc.t list
val descriptions_exn : _ t -> Async_rpc_kernel.Rpc.Description.t list
val print_shapes : _ t -> unit

Print a description of every supported protocol. This is useful for demonstrating the final set of protocols in an expect test.

val of_list : 'a t list -> 'a t

of_list ts results in a callee that implements everything that each element of ts implements.

implement_multi (of_list ts) ~f = List.concat_map ts ~f:(implement_multi ~f)
module Rpc : sig ... end

High level functions for working with callees in the style of Async.Rpc.Rpc.implement.

module Rpc' : sig ... end

High level functions for working with callees in the style of Async.Rpc.Rpc.implement'.

module Pipe_rpc : sig ... end

High level functions for working with callees in the style of Async.Rpc.Pipe_rpc.implement.

module Pipe_rpc_direct : sig ... end

High level functions for working with callees in the style of Async.Rpc.Pipe_rpc.implement_direct.

module State_rpc : sig ... end

High level functions for working with callees in the style of Async.Rpc.State_rpc.implement.

module One_way : sig ... end

High level functions for working with callees in the style of Async.Rpc.One_way.implement.

module Streamable_plain_rpc : sig ... end

High level functions for working with callees in the style of Streamable.Plain_rpc.implement.

module Streamable_pipe_rpc : sig ... end

High level functions for working with callees in the style of Streamable.Pipe_rpc.implement.

module Streamable_state_rpc : sig ... end

High level functions for working with callees in the style of Streamable.State_rpc.implement.

val map : 'a t -> f:('b -> 'a) -> 'b t

map t ~f transforms the model function supplied to implement_multi. Since in practice we are usually working with functions, it may be enlightening to think of the type as:

val map
  :  ('a1 -> 'b1) t
  -> f:(('a2 -> 'b2) -> 'a1 -> 'b1)
  -> ('a2 -> 'b2) t

Most of the time, you probably would prefer to use more specialized functions, such as Rpc.map_query and Rpc.map_response, instead of map.

implement_multi (map t ~f) ~f:g = implement_multi t ~f:(Fn.compose f g)
val map_query : ('a -> 'b) t -> f:('a -> 'c) -> ('c -> 'b) t

map_query is a specialization of map for the query type of a callee.

In practice, most implementations will return deferreds or other complex types, so you should prefer to use more specialized functions, such as Rpc.map_query.

implement_multi (map_query t ~f) ~f:g
= implement_multi t ~f:(fun s query -> g s (f query))
val map_response : ('a -> 'b) t -> f:('c -> 'b) -> ('a -> 'c) t

map_response is a specialization of map for the return type of an implementation.

In practice, most implementations will return deferreds or other complex types, so you should prefer to use more specialized functions, such as Rpc.map_response. map_response is intended to be used for more radical changes to an implementation, such as to change the type of rpc protocol.

implement_multi (map_response t ~f) ~f:g
= implement_multi t ~f:(fun s query -> f (g s query))
OCaml

Innovation. Community. Security.