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 <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
This commit is contained in:
parent
515bfa18fb
commit
1bf6b9f5a0
1 changed files with 6 additions and 13 deletions
|
@ -162,12 +162,11 @@ where
|
||||||
InodeData::Directory(DirectoryInodeData::Sparse(ref parent_digest, _)) => {
|
InodeData::Directory(DirectoryInodeData::Sparse(ref parent_digest, _)) => {
|
||||||
let directory = self
|
let directory = self
|
||||||
.tokio_handle
|
.tokio_handle
|
||||||
.block_on(self.tokio_handle.spawn({
|
.block_on({
|
||||||
let directory_service = self.directory_service.clone();
|
let directory_service = self.directory_service.clone();
|
||||||
let parent_digest = parent_digest.to_owned();
|
let parent_digest = parent_digest.to_owned();
|
||||||
async move { directory_service.as_ref().get(&parent_digest).await }
|
async move { directory_service.as_ref().get(&parent_digest).await }
|
||||||
}))
|
})?
|
||||||
.unwrap()?
|
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
warn!(directory.digest=%parent_digest, "directory not found");
|
warn!(directory.digest=%parent_digest, "directory not found");
|
||||||
// If the Directory can't be found, this is a hole, bail out.
|
// 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 span = info_span!("read", blob.digest = %blob_digest);
|
||||||
let _enter = span.enter();
|
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_service = self.blob_service.clone();
|
||||||
let blob_digest = blob_digest.clone();
|
let blob_digest = blob_digest.clone();
|
||||||
async move { blob_service.as_ref().open_read(&blob_digest).await }
|
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) => {
|
Ok(None) => {
|
||||||
warn!("blob not found");
|
warn!("blob not found");
|
||||||
Err(io::Error::from_raw_os_error(libc::EIO))
|
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;
|
let mut blob_reader = blob_reader.lock().await;
|
||||||
|
|
||||||
// seek to the offset specified, which is relative to the start of the file.
|
// 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?;
|
tokio::io::copy(&mut blob_reader.as_mut().take(size as u64), &mut buf).await?;
|
||||||
|
|
||||||
Ok(buf)
|
Ok(buf)
|
||||||
});
|
})?;
|
||||||
|
|
||||||
let buf = self.tokio_handle.block_on(task).unwrap()?;
|
|
||||||
|
|
||||||
w.write(&buf)
|
w.write(&buf)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue