make applying edits work correctly
turns out they weren't quite working due to me being a dummy and not awaiting my asyncs
This commit is contained in:
parent
55f12caf22
commit
8461812935
|
@ -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<Output = Result<(), ApplyFailed>> + 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(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue