OxL Справочник OxL
РусскийEnglish

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✓ проверяется в 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")
  }
}
Вывод
1
pub(api) fn subscribe() -> stream<Shared<T>, Lagged>

С версии. 1.0.0-beta

Возвращает

stream<Shared<T>, Lagged>

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/stream/stream.oxl:638

См. также