From 8461812935c819f9225d1a1e3375035675f82a15 Mon Sep 17 00:00:00 2001 From: liquidev Date: Sat, 23 Nov 2024 22:18:10 +0100 Subject: [PATCH] make applying edits work correctly turns out they weren't quite working due to me being a dummy and not awaiting my asyncs --- crates/treehouse/src/vfs/edit.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/treehouse/src/vfs/edit.rs b/crates/treehouse/src/vfs/edit.rs index c8524f0..8d784d5 100644 --- a/crates/treehouse/src/vfs/edit.rs +++ b/crates/treehouse/src/vfs/edit.rs @@ -1,6 +1,6 @@ use std::{error::Error, fmt, future::Future, path::PathBuf}; -use log::{error, info}; +use log::{debug, error, info}; use tokio::task::JoinSet; #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -36,26 +36,35 @@ impl Edit { pub fn apply(self) -> impl Future> + Send { async { match self { - Edit::NoOp => (), + Edit::NoOp => debug!("no op edit"), Edit::Write(edit_path, content) => { tokio::fs::write(&edit_path.path, &content) .await .inspect_err(|err| error!("write to {edit_path:?} failed: {err:?}")) .map_err(|_| ApplyFailed)?; + debug!("wrote {} bytes to {edit_path:?}", content.len()) } Edit::Seq(vec) => { + debug!("begin sequence of {} edits", vec.len()); + for edit in vec { Box::pin(edit.apply()).await?; } + + debug!("end sequence"); } Edit::All(vec) => { + debug!("begin parallel {} edits", vec.len()); + let mut set = JoinSet::new(); for edit in vec { set.spawn(edit.apply()); } - while let Some(result) = set.try_join_next() { + while let Some(result) = set.join_next().await { result.map_err(|_| ApplyFailed)??; } + + debug!("end parallel"); } Edit::Dry(edit) => edit.dry(), }