Hive.Mailbox
hive · API reference
Bounded closeable FIFO mailboxes.
A bounded, closeable FIFO mailbox over Eio.Stream.
Bounded by construction: a full mailbox blocks producers (backpressure). Closing is a flag consulted by producers; consumers drain via take_opt during shutdown.
type 'a tA mailbox carrying values of type 'a.
val create : int -> 'a tcreate capacity makes a mailbox holding up to capacity messages. capacity = 0 is a synchronous handoff. Raises Invalid_argument if capacity is negative.
ocaml]
let inbox = Hive.Mailbox.create 128val put : 'a t -> 'a -> (unit, [ `Closed ]) resultput t v enqueues v; blocks while the mailbox is full. Error Closed` once the mailbox is closed.
val take : 'a t -> 'atake t dequeues the oldest message, blocking while empty.
Use this from the single consumer fiber that owns the mailbox.
val take_opt : 'a t -> 'a optiontake_opt t dequeues without blocking; None when empty.
val close : 'a t -> unitclose t rejects subsequent puts. Queued messages remain takeable.
val is_closed : 'a t -> boolis_closed t reports whether future puts will be rejected.
val length : 'a t -> intCurrent queued message count. Intended for diagnostics and tests.
val capacity : 'a t -> intMaximum queued message count configured at create.