Remove randomness from GPUI2 block_with_timeout

This commit is contained in:
Antonio Scandurra 2023-10-30 12:10:36 +01:00
parent b3c3adab50
commit 25e882d72a

View file

@ -1,5 +1,5 @@
use crate::{AppContext, PlatformDispatcher}; use crate::{AppContext, PlatformDispatcher};
use futures::{channel::mpsc, pin_mut}; use futures::{channel::mpsc, pin_mut, FutureExt};
use smol::prelude::*; use smol::prelude::*;
use std::{ use std::{
fmt::Debug, fmt::Debug,
@ -162,20 +162,16 @@ impl Executor {
duration: Duration, duration: Duration,
future: impl Future<Output = R>, future: impl Future<Output = R>,
) -> Result<R, 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() { if duration.is_zero() {
return Err(future); return Err(future);
} }
let timeout = { let mut timer = self.timer(duration).fuse();
let future = &mut future; let timeout = async {
async { futures::select_biased! {
let timer = async { value = future => Ok(value),
self.timer(duration).await; _ = timer => Err(()),
Err(())
};
let future = async move { Ok(future.await) };
timer.race(future).await
} }
}; };
match self.block(timeout) { match self.block(timeout) {