use tokio::sync::mpsc; pub struct ClosableSender { origin: std::sync::Arc>>>, } impl Clone for ClosableSender { fn clone(&self) -> Self { Self { origin: self.origin.clone(), } } } impl ClosableSender { pub fn new(sender: mpsc::UnboundedSender) -> Self { Self { origin: std::sync::Arc::new(std::sync::RwLock::new(Some(sender))), } } pub fn get(&self) -> Option> { self.origin.read().unwrap().clone() } pub fn close(&mut self) { self.origin.write().unwrap().take(); } }