1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! # Event bus for broadcasting runtime events.
//!
//! [`Bus`] is a thin wrapper around [`tokio::sync::broadcast`] that provides non-blocking
//! event publishing from multiple sources (actors, runner, supervisor).
//!
//! ## Architecture
//!
//! ```text
//! Publishers (many): Subscriber (one):
//! Actor 1 ──┐
//! Actor 2 ──┼──────► Bus ───────► subscriber_listener ────► SubscriberSet
//! Actor N ──┤ (broadcast chan) (in Supervisor)
//! Runner ──┘
//! ```
//!
//! taskvisor uses a single internal listener that fans out events to multiple user-defined subscribers via `SubscriberSet`.
//!
//! ## Rules
//!
//! - **Non-blocking publish**: `publish()` never blocks; it calls `broadcast::Sender::send`.
//! - **Lag handling**: slow receivers get `RecvError::Lagged(n)` and skip `n` oldest items.
//! - **No persistence**: events are lost if there are no active subscribers at send time.
//! - **Bounded capacity**: a single ring buffer stores recent events for all receivers.
//!
//! ## Capacity behavior
//!
//! When the channel reaches capacity and new events are sent:
//! - Receivers that fell behind observe `RecvError::Lagged(n)` on the next `recv()`, indicating how many events were skipped.
//! - The ring buffer keeps only the most recent `capacity` events.
use Arc;
use broadcast;
use Event;
/// Broadcast channel for runtime events.
///
/// Thin wrapper over [`tokio::sync::broadcast`] that provides `publish`/`subscribe` API.
/// Multiple publishers can publish concurrently; subscribers receive clones of each event.
///
/// ### Properties
///
/// - **Non-blocking**: `publish()` returns immediately (send clones internally).
/// - **Cloneable**: cheap to clone (internally holds an `Arc`-backed sender).
/// - **Fire-and-forget**: no delivery or durability guarantees.
pub