OxL Reference

10.4 Broadcast — local fan-out

Broadcast<T> delivers every published item to all current subscribers.

oxl
let prices = Broadcast<Tick>(buffer: TICK_BUFFER, slow: .DropOldest, replay: 1)

scope {
  spawn { for await t in Exchange.feed() { prices.publish(t) } }
  spawn { for await t in prices.subscribe() { ui.render(t) } }
  spawn { for await t in prices.subscribe() { stats.add(t) } }
}

impl Market {
  rpc ticks() -> stream<Shared<Tick>, Lagged> => prices.subscribe()   // for every client
}
  • A subscriber receives the items published after subscribing, in publication order, plus up to replay last items at subscription time.
  • Items are shared without copying: a subscriber receives Shared<T> (= Arc<frozen T>). Over the network an item is encoded once for all connections.
  • The slow-subscriber policy slow:
PolicyBehaviour
.Blockpublish waits until space is freed at the slowest subscriber
.DropOldesta lagging subscriber loses old items; the number of losses is sub.lagged()
.Disconnectthe stream of a lagging subscriber ends with the error Lagged
  • prices.close() ends all subscriptions. prices.subscribers() is the number of subscribers.

See also

Source: docs/spec/oxl-standard.en.md