Receive group
New to the concept? See Tools — Mailbox first.
receive
Before After
receiver Slot receiver Slot
+-------------------+ +-------------------+
| null | | ItemHandle |
+-------------------+ +-------------------+
mbx.receive(&slot, null) Receiver holds ItemHandle
pub fn receive(self: *Mbox, slot: *Slot, timeout_ns: ?u64) (error{ Closed, Timeout, Wakeup } || Cancelable)!void
- Blocks until handle available.
nulltimeout = wait forever.timeout_ns = 0returnserror.Timeoutimmediately — equivalent totry_receive.- Moves the handle —
slot.*set to non-null. - OOB handles arrive first (front of queue).
wakeUpAll()called while blocked here — returnserror.Wakeup,slot.*stays null.- Multiple concurrent receivers compete for each handle.
- One receiver gets it.
- Order among waiters depends on the Io runtime — not guaranteed FIFO.
- Assert:
slot.* == null
try_receive
- Non-blocking.
- Returns true if handle received, false if queue empty.
- Assert:
slot.* == null
receive_batch
- Non-blocking.
- Takes everything from the queue at once.
- Returns an empty
ItemListif queue is currently empty. - Does not wait. Does not return error for empty.
The caller holds every item in that list — same duty as after close().
Free them, or put them back into a pool.