From b039b6efcb13d6574cc0b3d1c401e73c51bed6e1 Mon Sep 17 00:00:00 2001 From: Dorian Weber <weber@informatik.hu-berlin.de> Date: Mon, 15 Feb 2021 13:09:34 +0100 Subject: [PATCH] Fixed a bug with the channels. --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8c51b76..01be582 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> { -- GitLab