diff --git a/src/lib.rs b/src/lib.rs index 8c51b768d921bbe76c6337a8cf7c5fd8aafe80d7..01be5822d08052537b3d32d47d4504e9d4a3c3a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -671,6 +671,22 @@ impl<T: Unpin> Sender<T> { } } +impl<T> Drop for Sender<T> { + #[inline] + fn drop(&mut self) { + // check if there are still receivers + if let Some(chan) = self.0.upgrade() { + // check if we're the last sender to drop + if Rc::weak_count(&chan) == 1 { + // awake all of the waiting receivers so that they get to return + for process in chan.borrow_mut().waiting.drain(..) { + process.wake(); + } + } + } + } +} + impl<T: Unpin> Receiver<T> { /// Returns a future that can be awaited to receive a message. pub fn recv(&self) -> ReceiveFuture<T> {