OxL Reference

method Broadcast.subscribe

A new subscription: elements published from now on (after the replayed ones). Each subscription is its own stream; it ends with Lagged under .Disconnect when it falls behind.

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: 1 })
  hub.publish(Tick{ px: 2 })
  match sub.pullWithin(1s) {
    Pulled.Item(t) => print("{t.px}")
    _ => print("nothing")
  }
}
Output
1
pub(api) fn subscribe() -> stream<Shared<T>, Lagged>

Since. 1.0.0-beta

Returns

stream<Shared<T>, Lagged>

Effects

none declared (pure unless the body says otherwise)

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

See also