about summary refs log tree commit diff
path: root/tvix/castore/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-04-14T18·41+0300
committerflokli <flokli@flokli.de>2024-04-15T09·27+0000
commit1bf6b9f5a0caa5420ded4fba81646da9ea41bfb2 (patch)
tree9f84e908506ca820cae4ba51efad82ecdbfff9d0 /tvix/castore/src
parent515bfa18fbe2e4031ffb1ea1a5a45f67540856d5 (diff)
refactor(tvix/castore/fs): simplify some separate spawn and blocks r/7913
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 <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src')
-rw-r--r--tvix/castore/src/fs/mod.rs19
1 files 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)
     }