mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-19 19:14:53 +00:00
chore: get rid of deprecated funcrunner
This commit is contained in:
parent
5a9c03c11d
commit
258c6d5fae
2 changed files with 0 additions and 70 deletions
|
@ -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<String>,
|
||||
}
|
||||
|
||||
pub struct FuncRunner {
|
||||
output: Vec<String>,
|
||||
res: Option<bool>,
|
||||
thread: Option<JoinHandle<FuncRunnerOut>>,
|
||||
func: Box<dyn FnOnce() -> FuncRunnerOut + Send + Sync + 'static>,
|
||||
}
|
||||
|
||||
impl FuncRunner {
|
||||
pub fn new(func: Box<dyn FnOnce() -> 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<String> {
|
||||
let res = self.output.clone();
|
||||
self.output.clear();
|
||||
res
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue