Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use crate::{AppContext, PlatformDispatcher}; |
| 2 | −use futures::{channel::mpsc, pin_mut}; | |
| 2 | +use futures::{channel::mpsc, pin_mut, FutureExt}; | |
| 3 | 3 | use smol::prelude::*; |
| 4 | 4 | use std::{ |
| 5 | 5 | fmt::Debug, |
| @@ -162,20 +162,16 @@ impl Executor { · 156 unmodified lines | ||
| 162 | 162 | duration: Duration, |
| 163 | 163 | future: impl Future<Output = R>, |
| 164 | 164 | ) -> Result<R, impl Future<Output = R>> { |
| 165 | − let mut future = Box::pin(future); | |
| 165 | + let mut future = Box::pin(future.fuse()); | |
| 166 | 166 | if duration.is_zero() { |
| 167 | 167 | return Err(future); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | − let timeout = { | |
| 171 | − let future = &mut future; | |
| 172 | − async { | |
| 173 | − let timer = async { | |
| 174 | − self.timer(duration).await; | |
| 175 | − Err(()) | |
| 176 | − }; | |
| 177 | − let future = async move { Ok(future.await) }; | |
| 178 | − timer.race(future).await | |
| 170 | + let mut timer = self.timer(duration).fuse(); | |
| 171 | + let timeout = async { | |
| 172 | + futures::select_biased! { | |
| 173 | + value = future => Ok(value), | |
| 174 | + _ = timer => Err(()), | |
| 179 | 175 | } |
| 180 | 176 | }; |
| 181 | 177 | match self.block(timeout) { |