method Broadcast.publish
Delivers x to every current subscriber; under .Block it waits for room. A closed hub drops it.
Example:
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) timeComplexity. O(subscribers); under `.Block` it waits for room.
Since. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
x | T |
Effects
time
Defined in: std/stream/stream.oxl:612