Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Remove randomness from GPUI2 block_with_timeout

Antonio Scandurra25e882d72a1f
diff --git a/crates/gpui2/src/executor.rs b/crates/gpui2/src/executor.rs
index 104f40e8f13..b2ba710fe72 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<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) {