diff options
author | 2024-04-17 15:54:12 +0200 | |
---|---|---|
committer | 2024-04-17 15:54:12 +0200 | |
commit | a05b8044a9a82c1802d4d97f1723e24b9d9dad9c (patch) | |
tree | f752964abac06a65e537b2cbe50222076d9ed71f | |
parent | ba705d63dd52160e5c0b90024bb2d6f95e3f6762 (diff) | |
download | iced-a05b8044a9a82c1802d4d97f1723e24b9d9dad9c.tar.gz iced-a05b8044a9a82c1802d4d97f1723e24b9d9dad9c.tar.bz2 iced-a05b8044a9a82c1802d4d97f1723e24b9d9dad9c.zip |
Fix `SelectNextSome` poll after termination panic in `iced_winit::Proxy`
-rw-r--r-- | winit/src/proxy.rs | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/winit/src/proxy.rs b/winit/src/proxy.rs index a35e8a27..3edc30ad 100644 --- a/winit/src/proxy.rs +++ b/winit/src/proxy.rs @@ -1,6 +1,6 @@ use crate::futures::futures::{ channel::mpsc, - stream, + select, task::{Context, Poll}, Future, Sink, StreamExt, }; @@ -31,40 +31,33 @@ impl<Message: 'static> Proxy<Message> { pub fn new( raw: winit::event_loop::EventLoopProxy<Message>, ) -> (Self, impl Future<Output = ()>) { - let (notifier, processed) = mpsc::channel(Self::MAX_SIZE); - let (sender, receiver) = mpsc::channel(Self::MAX_SIZE); + let (notifier, mut processed) = mpsc::channel(Self::MAX_SIZE); + let (sender, mut receiver) = mpsc::channel(Self::MAX_SIZE); let proxy = raw.clone(); let worker = async move { - enum Item<T> { - MessageProduced(T), - BatchProcessed(usize), - } - - let mut receiver = receiver.map(Item::MessageProduced); - let mut processed = processed.map(Item::BatchProcessed); - let mut count = 0; loop { if count < Self::MAX_SIZE { - let mut stream = - stream::select(receiver.by_ref(), processed.by_ref()); - - match stream.select_next_some().await { - Item::MessageProduced(message) => { + select! { + message = receiver.select_next_some() => { let _ = proxy.send_event(message); - count += 1; + + } + amount = processed.select_next_some() => { + count = count.saturating_sub(amount); } - Item::BatchProcessed(amount) => { + complete => break, + } + } else { + select! { + amount = processed.select_next_some() => { count = count.saturating_sub(amount); } + complete => break, } - } else if let Item::BatchProcessed(amount) = - processed.select_next_some().await - { - count = count.saturating_sub(amount); } } }; |