summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <github@bigly.dog>2024-03-21 10:56:23 -0700
committerroot <github@bigly.dog>2024-03-21 10:56:23 -0700
commitb4851087651b24a925cb4245fc8564cac9b255d4 (patch)
tree28455b18cd6eb6e37b0e2aa3393f2d049240291b
parentf3c18f70689c445c4aaf79fb63c4e60d21f26b93 (diff)
remove abort
-rw-r--r--src/main.rs25
-rw-r--r--src/subprocess.rs22
-rw-r--r--src/types.rs34
3 files changed, 24 insertions, 57 deletions
diff --git a/src/main.rs b/src/main.rs
index f44dba4..a2e9b51 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -34,7 +34,7 @@ use {
thread::available_parallelism,
},
tokio::runtime::Builder,
- types::{Abort, Fail},
+ types::Fail,
};
async fn run(threads: usize) -> Result<(), Fail> {
@@ -62,24 +62,11 @@ fn main() -> impl Termination {
.build()
.expect("runtime failure");
- let errors = rt.block_on(async {
- let abort = Abort::new();
- if let Err(err) = run(threads).await {
- let mut errs = abort.fin().await;
- errs.push(err);
- errs
- } else {
- abort.fin().await
- }
- });
-
- match errors[..] {
- [] => ExitCode::SUCCESS,
- [Fail::Interrupt] => ExitCode::from(130),
- _ => {
- for err in errors {
- eprintln!("{}", Colour::Red.paint(format!("{err}")));
- }
+ match rt.block_on(run(threads)).err() {
+ None => ExitCode::SUCCESS,
+ Some(Fail::Interrupt) => ExitCode::from(130),
+ Some(e) => {
+ eprintln!("{}", Colour::Red.paint(format!("{e}")));
ExitCode::FAILURE
}
}
diff --git a/src/subprocess.rs b/src/subprocess.rs
index 427613c..99f492f 100644
--- a/src/subprocess.rs
+++ b/src/subprocess.rs
@@ -30,10 +30,22 @@ pub fn stream_into(
where
{
let buf = BufWriter::new(writer);
- try_unfold((buf, stream, path), |mut s| async {
- match s.1.next().await {
- None => Ok(None),
- Some(Err(e)) => Err(e),
+ try_unfold((stream, buf, path), |mut s| async {
+ match s.0.next().await {
+ None => {
+ s.1
+ .shutdown()
+ .await
+ .map_err(|e| Fail::IO(s.2.clone(), e.kind()))?;
+ Ok(None)
+ }
+ Some(Err(e)) => {
+ s.1
+ .shutdown()
+ .await
+ .map_err(|e| Fail::IO(s.2.clone(), e.kind()))?;
+ Err(e)
+ }
Some(Ok(print)) => {
#[cfg(target_family = "unix")]
let bytes = {
@@ -45,7 +57,7 @@ where
let tmp = print.to_string_lossy();
tmp.as_bytes()
};
- s.0
+ s.1
.write_all(bytes)
.await
.map_err(|e| Fail::IO(s.2.clone(), e.kind()))?;
diff --git a/src/types.rs b/src/types.rs
index a375467..0da5600 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -10,7 +10,7 @@ use {
path::PathBuf,
sync::Arc,
},
- tokio::{sync::Notify, task::JoinError},
+ tokio::task::JoinError,
};
#[derive(Clone, Debug)]
@@ -53,35 +53,3 @@ impl From<BuildError> for Fail {
Self::BuildError(e)
}
}
-
-pub struct Abort {
- errors: Mutex<Vec<Fail>>,
- rx: Notify,
-}
-
-impl Abort {
- pub fn new() -> Arc<Self> {
- Arc::new(Self {
- errors: Mutex::new(Vec::default()),
- rx: Notify::new(),
- })
- }
-
- pub async fn fin(&self) -> Vec<Fail> {
- self.errors.lock().await.to_vec()
- }
-
- pub async fn send(&self, fail: Fail) {
- let mut errors = self.errors.lock().await;
- errors.push(fail);
- self.rx.notify_waiters();
- }
-
- pub async fn notified(&self) {
- let errors = self.errors.lock().await;
- if errors.len() > 0 {
- } else {
- self.rx.notified().await;
- }
- }
-}