diff --git a/crates/gpui2/src/executor.rs b/crates/gpui2/src/executor.rs index 104f40e8f1..b2ba710fe7 100644 --- a/crates/gpui2/src/executor.rs +++ b/crates/gpui2/src/executor.rs @@ -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, ) -> Result> { - 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) {