OxL Reference

data Broadcast

Local fan-out hub: every published element reaches every current subscriber as a Shared<T> (no copies). A Broadcast is a cheap handle (clone() shares the hub) and can be used from any task. The last handle going away closes it.

Example:

oxl✓ checked in CI
use std.stream { Broadcast }

data Tick { px: i32 }

fn main() io, time {
  let hub = Broadcast<Tick>.new(buffer: 4)
  var sub = hub.subscribe()
  hub.publish(Tick{ px: 5 })
  match sub.pullWithin(1s) {
    Pulled.Item(t) => print("{t.px}")
    _ => print("nothing")
  }
}
Output
5
@builtin("Broadcast") pub(api) data Broadcast<T>

Thread safety. a cheap handle; `clone()` shares the hub and it can be used from any task.

Since. 1.0.0-beta

Methods

new(buffer: usize, slow: SlowPolicy, replay: usize) -> Self
buffer unread elements per subscriber (at least 1); a new subscriber first receives up to replay of the most recent elements (at most buffer).
publish(x: T) time
Delivers x to every current subscriber; under .Block it waits for room.
subscribe() -> stream<Shared<T>, Lagged>
A new subscription
subscribers() -> usize
Number of live subscriptions.
close()
Ends every subscription (after the elements it still has).
clone() -> Broadcast<T>
Another handle of the same hub.

Defined in: std/stream/stream.oxl:561

See also