From d78708ce24df5ede12997f5491103696c24f0e03 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Mar 2024 15:03:05 +0100 Subject: [PATCH] Clarify --- lib/storage/tool_cache.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/storage/tool_cache.rs b/lib/storage/tool_cache.rs index dcf9864..6f04692 100644 --- a/lib/storage/tool_cache.rs +++ b/lib/storage/tool_cache.rs @@ -166,10 +166,10 @@ impl ToolCache { } } -// NOTE: Using std::fs here and passing a reader to serde_json lets us -// deserialize the cache faster and without storing the file in memory. async fn load_impl(path: PathBuf) -> AftmanResult { - Ok(spawn_blocking(move || { + // NOTE: Using std::fs here and passing a reader to serde_json lets us + // deserialize the cache faster and without storing the file in memory. + let result = spawn_blocking(move || { use std::{ fs::File, io::{BufReader, Error}, @@ -177,12 +177,11 @@ async fn load_impl(path: PathBuf) -> AftmanResult { let reader = BufReader::new(File::open(path)?); let this: ToolCache = serde_json::from_reader(reader)?; Ok::<_, Error>(this) - }) - .await? - .unwrap_or_default()) + }); + + Ok(result.await?.unwrap_or_default()) } -// Same as in our load implementation, see notes above. async fn save_impl(path: PathBuf, cache: &ToolCache) -> AftmanResult<()> { // NOTE: We save using sorted json arrays here, which is // compatible with the deserialize implementation for DashSet, @@ -192,7 +191,8 @@ async fn save_impl(path: PathBuf, cache: &ToolCache) -> AftmanResult<()> { "installed": cache.all_installed(), }); - spawn_blocking(move || { + // Same as in our load implementation, see notes there. + let result = spawn_blocking(move || { use std::{ fs::{create_dir_all, File}, io::{BufWriter, Error}, @@ -201,8 +201,8 @@ async fn save_impl(path: PathBuf, cache: &ToolCache) -> AftmanResult<()> { let writer = BufWriter::new(File::create(path)?); serde_json::to_writer(writer, &json)?; Ok::<_, Error>(()) - }) - .await??; + }); + result.await??; Ok(()) }