mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-03 16:15:46 +00:00
feat: sync join runners
This commit is contained in:
parent
f2cfdabd11
commit
d9b0412aca
1 changed files with 20 additions and 6 deletions
|
@ -113,6 +113,15 @@ impl Runner {
|
||||||
self.threads.push(logger_thread!(stderr, stderr_sender));
|
self.threads.push(logger_thread!(stderr, stderr_sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn join_threads(&mut self) {
|
||||||
|
loop {
|
||||||
|
match self.threads.pop() {
|
||||||
|
None => break,
|
||||||
|
Some(thread) => thread.join().expect_dialog("Failed to join reader thread"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn terminate(&mut self) {
|
pub fn terminate(&mut self) {
|
||||||
if self.status() != RunnerStatus::Running {
|
if self.status() != RunnerStatus::Running {
|
||||||
return;
|
return;
|
||||||
|
@ -128,15 +137,20 @@ impl Runner {
|
||||||
.expect_dialog("Could not convert pid to u32"),
|
.expect_dialog("Could not convert pid to u32"),
|
||||||
);
|
);
|
||||||
kill(child_pid, SIGTERM).expect_dialog("Could not send sigterm to process");
|
kill(child_pid, SIGTERM).expect_dialog("Could not send sigterm to process");
|
||||||
loop {
|
self.join_threads();
|
||||||
match self.threads.pop() {
|
|
||||||
None => break,
|
|
||||||
Some(thread) => thread.join().expect_dialog("Failed to join reader thread"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
proc.wait().expect_dialog("Failed to wait for process");
|
proc.wait().expect_dialog("Failed to wait for process");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn join(&mut self) {
|
||||||
|
let process = self.process.take();
|
||||||
|
if process.is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut proc = process.unwrap();
|
||||||
|
proc.wait().expect_dialog("Failed to wait for process");
|
||||||
|
self.join_threads();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn status(&mut self) -> RunnerStatus {
|
pub fn status(&mut self) -> RunnerStatus {
|
||||||
match &mut self.process {
|
match &mut self.process {
|
||||||
None => RunnerStatus::Stopped,
|
None => RunnerStatus::Stopped,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue