From 1bf6b9f5a0caa5420ded4fba81646da9ea41bfb2 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 14 Apr 2024 21:41:17 +0300 Subject: refactor(tvix/castore/fs): simplify some separate spawn and blocks We can just pass an async move closure to `self.tokio_handle.block_on` and make this a bit shorter. Change-Id: Iba674f34f22ba7a7de7c5bae59d64584884cb17c Reviewed-on: https://cl.tvl.fyi/c/depot/+/11423 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/castore/src/fs/mod.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tvix/castore/src/fs/mod.rs b/tvix/castore/src/fs/mod.rs index 8731c8374df9..53f74fd400ed 100644 --- a/tvix/castore/src/fs/mod.rs +++ b/tvix/castore/src/fs/mod.rs @@ -162,12 +162,11 @@ where InodeData::Directory(DirectoryInodeData::Sparse(ref parent_digest, _)) => { let directory = self .tokio_handle - .block_on(self.tokio_handle.spawn({ + .block_on({ let directory_service = self.directory_service.clone(); let parent_digest = parent_digest.to_owned(); async move { directory_service.as_ref().get(&parent_digest).await } - })) - .unwrap()? + })? .ok_or_else(|| { warn!(directory.digest=%parent_digest, "directory not found"); // If the Directory can't be found, this is a hole, bail out. @@ -505,15 +504,11 @@ where let span = info_span!("read", blob.digest = %blob_digest); let _enter = span.enter(); - let task = self.tokio_handle.spawn({ + match self.tokio_handle.block_on({ let blob_service = self.blob_service.clone(); let blob_digest = blob_digest.clone(); async move { blob_service.as_ref().open_read(&blob_digest).await } - }); - - let blob_reader = self.tokio_handle.block_on(task).unwrap(); - - match blob_reader { + }) { Ok(None) => { warn!("blob not found"); Err(io::Error::from_raw_os_error(libc::EIO)) @@ -594,7 +589,7 @@ where } }; - let task = self.tokio_handle.spawn(async move { + let buf = self.tokio_handle.block_on(async move { let mut blob_reader = blob_reader.lock().await; // seek to the offset specified, which is relative to the start of the file. @@ -619,9 +614,7 @@ where tokio::io::copy(&mut blob_reader.as_mut().take(size as u64), &mut buf).await?; Ok(buf) - }); - - let buf = self.tokio_handle.block_on(task).unwrap()?; + })?; w.write(&buf) } -- cgit 1.4.1