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

method Broadcast.publish

Delivers x to every current subscriber; under .Block it waits for room. A closed hub drops it.

Example:

oxl✓ проверяется в 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}")
}
Вывод
14
pub(api) fn publish(x: T) time

Сложность. O(subscribers); under `.Block` it waits for room.

С версии. 1.0.0-beta

Параметры

ИмяТип
xT

Эффекты

time

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

См. также