Start restructuring WrapMap with simpler concurrency

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2021-07-22 16:21:42 -07:00
co-authored by Nathan Sobo
parent 80f13dd737
commit 5d22c6c4bd
6 changed files with 530 additions and 581 deletions
+11 -5
View File
@@ -385,14 +385,14 @@ impl Background {
}
}
pub fn block_on<F, T>(&self, timeout: Duration, future: F) -> Option<T>
pub fn block_with_timeout<F, T>(&self, timeout: Duration, mut future: F) -> Result<T, F>
where
T: 'static,
F: Future<Output = T>,
F: 'static + Unpin + Future<Output = T>,
{
match self {
let output = match self {
Self::Production { .. } => {
smol::block_on(async move { util::timeout(timeout, future).await.ok() })
smol::block_on(util::timeout(timeout, Pin::new(&mut future))).ok()
}
Self::Deterministic(executor) => {
let max_ticks = {
@@ -400,8 +400,14 @@ impl Background {
let range = state.block_on_ticks.clone();
state.rng.gen_range(range)
};
executor.block_on(max_ticks, future)
executor.block_on(max_ticks, Pin::new(&mut future))
}
};
if let Some(output) = output {
Ok(output)
} else {
Err(future)
}
}