Values are retained until all receivers have read them, or evicted when the
bounded buffer wraps around. Receivers that fall behind get RecvError::Lagged.
#include <xpp/sync/broadcast.h>
xpp::EventLoop loop;
xpp::WaitScope scope(loop);
auto [tx, rx1] = xpp::sync::broadcast::channel<std::string>(16);
auto rx2 = tx.subscribe();
tx.send("hello");
tx.send("world");
// Both receivers see both values
auto v1 = rx1.recv().await(); // Ok("hello")
auto v2 = rx2.recv().await(); // Ok("hello")
auto v3 = rx1.recv().await(); // Ok("world")
auto v4 = rx2.recv().await(); // Ok("world")
// Late subscriber only sees future values
auto rx3 = tx.subscribe();
tx.send("!");
auto v5 = rx3.recv().await(); // Ok("!") — didn't see hello/world
auto [tx, rx] = xpp::sync::broadcast::channel<int>(2);
tx.send(1);
tx.send(2);
tx.send(3); // buffer full → 1 is evicted
auto r = rx.recv().await();
if (r.is_err()) {
// RecvError::Lagged — values were lost
// Position auto-resets to current head, can continue
}
auto v = rx.recv().await(); // Ok(2)
auto v = rx.recv().await(); // Ok(3)