// Adapted from: https://github.com/tokio-rs/mini-redis/blob/069a8e5ee0de445ad3e642548d196ef6b4fa8bc1/src/shutdown.rs
usetokio::sync::broadcast;pubstructShutdown{/// The receive half of the channel used to listen for shutdown.
notify:broadcast::Receiver<i32>,
received:bool,
}implShutdown{/// Create a new `Shutdown` backed by the given `broadcast::Receiver`.
pubfnnew(notify:broadcast::Receiver<i32>)->Self{Self{
notify,
received:false,}}pubfnreplicate(&self)->Self{Self{
notify:self.notify.resubscribe(),
received:self.received,}}/// Receive the shutdown notice, waiting if necessary.
pub async fnrecv(&mutself){ifself.received {return;}// Cannot receive a "lag error" as only one value is ever sent.
let_=self.notify.recv().await;self.received =true;}}