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
use super::broadcast::Receiver;
use super::AttachedShutdown;
#[cfg(test)]
use super::broadcast::error::TryRecvError;
#[derive(Debug)]
pub struct ShutdownReceiver {
pub(super) receiver: Receiver<()>,
}
impl ShutdownReceiver {
pub fn register<F>(self, future: F) -> AttachedShutdown<F> {
AttachedShutdown {
receiver: self,
future,
}
}
pub async fn wait(mut self) {
let _ = self.receiver.recv().await;
}
#[cfg(test)]
pub(crate) fn try_recv(&mut self) -> Result<(), TryRecvError> {
self.receiver.try_recv()
}
}
impl Clone for ShutdownReceiver {
fn clone(&self) -> Self {
Self {
receiver: self.receiver.resubscribe(),
}
}
}