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 ... endCompletion state shared by workers, tasks and supervisors.
module Addr : sig ... endTyped send capabilities.
module Mailbox : sig ... endBounded closeable FIFO mailboxes.
module Effects : sig ... endHive's small direct-style effect set.
module Worker : sig ... endLow-level fibers with typed mailboxes.
module Server : sig ... endGenServer-style pure-callback workers.
module Task : sig ... endOne-shot background work with observable outcomes.
module Scheduler : sig ... endCancellable one-shot and periodic timers.
module Supervisor : sig ... endOTP-style supervision trees.
module Registry : sig ... endLocal type-safe name registry.
module Group : sig ... endLocal process groups.
module Pubsub : sig ... endPubsub capability and in-process implementation.
val sleep : float -> unitsleep 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)