Change summary
crates/gpui2/src/executor.rs | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
Detailed changes
@@ -1,5 +1,5 @@
use crate::{AppContext, PlatformDispatcher};
-use futures::{channel::mpsc, pin_mut};
+use futures::{channel::mpsc, pin_mut, FutureExt};
use smol::prelude::*;
use std::{
fmt::Debug,
@@ -162,20 +162,16 @@ impl Executor {
duration: Duration,
future: impl Future<Output = R>,
) -> Result<R, impl Future<Output = R>> {
- let mut future = Box::pin(future);
+ let mut future = Box::pin(future.fuse());
if duration.is_zero() {
return Err(future);
}
- let timeout = {
- let future = &mut future;
- async {
- let timer = async {
- self.timer(duration).await;
- Err(())
- };
- let future = async move { Ok(future.await) };
- timer.race(future).await
+ let mut timer = self.timer(duration).fuse();
+ let timeout = async {
+ futures::select_biased! {
+ value = future => Ok(value),
+ _ = timer => Err(()),
}
};
match self.block(timeout) {