OxL Reference

method Broadcast.publish

Delivers x to every current subscriber; under .Block it waits for room. A closed hub drops 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 a = hub.subscribe()
  var b = hub.subscribe()
  hub.publish(Tick{ px: 7 })
  var total = 0
  match a.pullWithin(1s) {
    Pulled.Item(t) => total += t.px
    _ => {}
  }
  match b.pullWithin(1s) {
    Pulled.Item(t) => total += t.px
    _ => {}
  }
  print("{total}")
}
Output
14
pub(api) fn publish(x: T) time

Complexity. O(subscribers); under `.Block` it waits for room.

Since. 1.0.0-beta

Parameters

NameType
xT

Effects

time

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

See also