package riot

  1. Overview
  2. Docs

Riot

module Ref : sig ... end
module Pid : sig ... end
module Message : sig ... end
module Process : sig ... end
module Application : sig ... end

A Riot `Application` can be used to encapsulate functionality that must share the same lifecycle. For example, the `Riot.Logger` is an Application.

val random : unit -> Stdlib.Random.State.t

Returnts the current random state from a scheduler.

val yield : unit -> unit

Suspends execution of the current process and returns control to the scheduler

val sleep : float -> unit

sleep t Suspends execution of the current process for at least `t` seconds. `t` is a float so it supports subsecond values: `0.001` is 1 millisecond.

val self : unit -> Pid.t

Returns the process identifier (pid) for the current process

val process_flag : Process.process_flag -> unit
val exit : Pid.t -> Process.exit_reason -> unit

Sends an exit signal to the process pid, to exit with reason exit_reason

val send : Pid.t -> Message.t -> unit

Sends a message to process with this pid.

exception Invalid_destination of string
val send_by_name : name:string -> Message.t -> unit

Sends a message to a process registered with name. If name is not a valid destination for a message, this function raises an Invalid_destination name exception.

val spawn : (unit -> unit) -> Pid.t

Spawns a new process.

Spawns a new process and links it to the current process before returning.

exception Name_already_registered of string * Pid.t
val register : string -> Pid.t -> unit

register name pid registers a process by a given name. The name will be uniquely associated to this process and attempting to register the same name twice will result in an exception Name_already_registered being raised.

val unregister : string -> unit

unregister name frees a name and allows it to be re-registered. If the name was not registered before, this operation does nothing.

Links the current process and the process pid together.

val monitor : Pid.t -> Pid.t -> unit

Makes pid1 a monitor of pid2.

When pid2 terminates, pid1 will receive a Processes.Messages.Monitor(Process_down(pid2)) message.

val processes : unit -> (Pid.t * Process.t) Stdlib.Seq.t

`processes ()` will list all the processes currently alive.

val is_process_alive : Pid.t -> bool

Returns true if the process pid is still alive.

val wait_pids : Pid.t list -> unit

Await all processes in the list to termimante.

val receive : ?ref:unit Ref.t -> unit -> Message.t

receive () will return the first message in the process mailbox.

This function will suspend a process that has an empty mailbox, and the process will remain asleep until a message is delivered to it.

### Selective Receive

If a `ref` was passed, then `receive ref ()` will skip all messages created before the creation of this `Ref.t` value, and will only return newer messages.

This is useful to skip the queue, but not remove any of the messages before it. Those messages will be delivered in-order in future calls to `receive ()`.

val shutdown : unit -> unit

Gracefully shuts down the runtime. Any non-yielding process will block this.

val run : ?rnd:Stdlib.Random.State.t -> ?workers:int -> (unit -> unit) -> unit

Start the Riot runtime using function main to boot the system

val start : ?rnd:Stdlib.Random.State.t -> ?workers:int -> apps:(module Application.Intf) list -> unit -> unit

Start the Riot runtime with a series of applications.

Each application will be started in the same order as specified, and if any application fails to start up, the system will be shutdown.

Once the applications are started, they will all be monitored until they are all terminated. Only then will the runtime shutdown.

val trace_send : (Pid.t -> Process.t -> Message.t -> unit) -> unit
val trace_proc_run : (int -> Process.t -> unit) -> unit
module Gen_server : sig ... end
module Supervisor : sig ... end
module Telemetry : sig ... end
module Logger : sig ... end
module Fd : sig ... end
module IO : sig ... end
module File : sig ... end
module Net : sig ... end
module Timer : sig ... end
module Queue : sig ... end
OCaml

Innovation. Community. Security.