Fix SelectNextSome poll after termination panic in iced_winit::Proxy
This commit is contained in:
parent
ba705d63dd
commit
a05b8044a9
1 changed files with 15 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::futures::futures::{
|
use crate::futures::futures::{
|
||||||
channel::mpsc,
|
channel::mpsc,
|
||||||
stream,
|
select,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
Future, Sink, StreamExt,
|
Future, Sink, StreamExt,
|
||||||
};
|
};
|
||||||
|
|
@ -31,40 +31,33 @@ impl<Message: 'static> Proxy<Message> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
raw: winit::event_loop::EventLoopProxy<Message>,
|
raw: winit::event_loop::EventLoopProxy<Message>,
|
||||||
) -> (Self, impl Future<Output = ()>) {
|
) -> (Self, impl Future<Output = ()>) {
|
||||||
let (notifier, processed) = mpsc::channel(Self::MAX_SIZE);
|
let (notifier, mut processed) = mpsc::channel(Self::MAX_SIZE);
|
||||||
let (sender, receiver) = mpsc::channel(Self::MAX_SIZE);
|
let (sender, mut receiver) = mpsc::channel(Self::MAX_SIZE);
|
||||||
let proxy = raw.clone();
|
let proxy = raw.clone();
|
||||||
|
|
||||||
let worker = async move {
|
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;
|
let mut count = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if count < Self::MAX_SIZE {
|
if count < Self::MAX_SIZE {
|
||||||
let mut stream =
|
select! {
|
||||||
stream::select(receiver.by_ref(), processed.by_ref());
|
message = receiver.select_next_some() => {
|
||||||
|
|
||||||
match stream.select_next_some().await {
|
|
||||||
Item::MessageProduced(message) => {
|
|
||||||
let _ = proxy.send_event(message);
|
let _ = proxy.send_event(message);
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
Item::BatchProcessed(amount) => {
|
amount = processed.select_next_some() => {
|
||||||
count = count.saturating_sub(amount);
|
count = count.saturating_sub(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue