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