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 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) {