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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use PicoQ;
use ;
/// A blocking subscriber that receives messages from a topic.
///
/// `Subscriber` owns an internal FIFO queue and provides:
/// - **`recv`**: blocks until a message is available.
/// - **`push`**: blocks when the queue is full (if backpressure is enabled).
///
/// This type is designed to be used behind an `Arc` and shared safely
/// across threads.
///
/// # Backpressure
/// Backpressure is enabled when the underlying queue has a capacity (`cap > 0`).
/// - Producers calling [`push`] will block when the queue is full.
/// - Consumers calling [`recv`] will block when the queue is empty.
///
/// # Thread Safety
/// - The queue is protected by a `Mutex`.
/// - Two condition variables are used:
/// - `not_empty`: wakes waiting consumers when a message is pushed.
/// - `not_full`: wakes waiting producers when space becomes available.
///
/// # Typical Usage
/// A `Subscriber` is usually created and managed by a pub/sub broker and
/// returned as an `Arc<Subscriber<T>>`:
///
/// ```no_run
/// let sub = Subscriber::<i32>::new(10);
///
/// // Producer thread:
/// sub.push(Arc::new(42));
///
/// // Consumer thread:
/// let value = sub.recv();
/// ```