package riot

  1. Overview
  2. Docs
type 'res req = ..

req is the type of all generic server requests and responses.

When defining a new generic server you want to extend this with the your custom request types, including the response type in its type variable. Like this:

open Riot
type _ Gen_server.req +=
  | Is_connected : bool Gen_server.req
  | Profile : profile_req -> profile_res Gen_server.req
type 'state init_result =
  1. | Ok of 'state
    (*

    use this value to enter the main loop with state 'state

    *)
  2. | Error
    (*

    use this value to crash the process and notify a supervisor of it

    *)
  3. | Ignore
    (*

    use this value to exit the process normally

    *)

state init_result is used to initialize a new generic server.

module type Impl = sig ... end

Impl is the module type of the generic server base implementations. You can use this type when defining new gen servers like this:

type ('args, 'state) impl = (module Impl with type args = 'args and type state = 'state)
val call : Pid.t -> 'res req -> 'res

call pid req will send a type-safe request req to the generic server behind pid that is guaranteed to return a respone with type `'res`

This function will block the current process until a response arrives.

TODO(leostera): add ?timeout param

start_link (module S) args will spawn and link a new process that will act as a generic server over the server implementation of S, initialized with args arguments.

OCaml

Innovation. Community. Security.