Hive

hive · API reference

Hive: typed workers, servers, supervision, tasks and local coordination.

The base hive library is local by default. A worker is an Eio fiber with a typed mailbox; addresses are typed send capabilities; servers add request/reply callbacks and actions-as-data; supervisors restart children according to OTP-style strategies.

Open the package module or refer to submodules explicitly:

ocaml]
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
  let task = Hive.Task.async ~sw (fun () -> 21 * 2) in
  match Hive.Task.await task with
  | Hive.Outcome.Completed n -> traceln "answer=%d" n
  | Hive.Outcome.Failed exn -> raise exn
  | Hive.Outcome.Cancelled -> traceln "cancelled"
module Outcome : sig ... end

Completion state shared by workers, tasks and supervisors.

module Addr : sig ... end

Typed send capabilities.

module Mailbox : sig ... end

Bounded closeable FIFO mailboxes.

module Effects : sig ... end

Hive's small direct-style effect set.

module Worker : sig ... end

Low-level fibers with typed mailboxes.

module Server : sig ... end

GenServer-style pure-callback workers.

module Task : sig ... end

One-shot background work with observable outcomes.

module Scheduler : sig ... end

Cancellable one-shot and periodic timers.

module Supervisor : sig ... end

OTP-style supervision trees.

module Registry : sig ... end

Local type-safe name registry.

module Group : sig ... end

Local process groups.

module Pubsub : sig ... end

Pubsub capability and in-process implementation.

val sleep : float -> unit

sleep seconds is Effects.sleep re-exported at the package root.

It can be called from a worker or server callback when the runtime installed an effect handler with a clock:

ocaml]
let worker =
  Hive.Worker.spawn ~sw ~clock:(Hive.Effects.Clock clock) (fun _ msg ->
    Hive.sleep 0.1;
    traceln "processed %s" msg)