From 258c6d5faec7db9431b4d632920454e309155044 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Thu, 1 Aug 2024 19:35:19 +0200 Subject: [PATCH] chore: get rid of deprecated funcrunner --- src/func_runner.rs | 69 ---------------------------------------------- src/main.rs | 1 - 2 files changed, 70 deletions(-) delete mode 100644 src/func_runner.rs diff --git a/src/func_runner.rs b/src/func_runner.rs deleted file mode 100644 index 7aa40b7..0000000 --- a/src/func_runner.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::runner::{Runner, RunnerStatus}; -use std::{ - mem, - thread::{self, JoinHandle}, -}; - -#[derive(Debug, Clone, Default)] -pub struct FuncRunnerOut { - pub success: bool, - pub out: Vec, -} - -pub struct FuncRunner { - output: Vec, - res: Option, - thread: Option>, - func: Box FuncRunnerOut + Send + Sync + 'static>, -} - -impl FuncRunner { - pub fn new(func: Box FuncRunnerOut + Send + Sync + 'static>) -> Self { - FuncRunner { - output: Vec::new(), - thread: None, - res: None, - func, - } - } -} - -impl Runner for FuncRunner { - fn start(&mut self) { - if self.res.is_some() { - panic!("Cannot start a FuncRunner twice!"); - } - let f = mem::replace(&mut self.func, Box::new(FuncRunnerOut::default)); - self.thread = Some(thread::spawn(f)); - } - - fn status(&mut self) -> RunnerStatus { - if let Some(res) = self.res { - if res { - return RunnerStatus::Stopped(Some(0)); - } - return RunnerStatus::Stopped(Some(1)); - } - if let Some(t) = self.thread.take() { - if t.is_finished() { - let out = t.join().expect("Failed to join thread"); - self.res = Some(out.success); - self.output = out.out; - return self.status(); - } - self.thread = Some(t); - return RunnerStatus::Running; - } - RunnerStatus::Stopped(None) - } - - fn consume_output(&mut self) -> String { - self.consume_rows().concat() - } - - fn consume_rows(&mut self) -> Vec { - let res = self.output.clone(); - self.output.clear(); - res - } -} diff --git a/src/main.rs b/src/main.rs index ecdfae9..ab31a6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,6 @@ pub mod downloader; pub mod env_var_descriptions; pub mod file_builders; pub mod file_utils; -pub mod func_runner; pub mod gpu_profile; pub mod is_appimage; pub mod linux_distro;