refactor: remove uneccessary is_running load

This commit is contained in:
Jack Wills
2024-11-15 16:30:02 +00:00
parent f0b1145651
commit 76ccf7c006
5 changed files with 8 additions and 45 deletions
+1
View File
@@ -133,6 +133,7 @@ impl ContainerPorts {
.count()
}
/// Return as tuple of Strings, ip address, private port, and public port
pub fn print(&self) -> (String, String, String) {
(
self.ip
-8
View File
@@ -8,14 +8,6 @@ use tokio::sync::oneshot::Sender;
pub enum DockerMessage {
ConfirmDelete(ContainerId),
Control((DockerCommand, ContainerId)),
// Delete(ContainerId),
Exec(Sender<Arc<Docker>>),
// Pause(ContainerId),
Quit,
// Restart(ContainerId),
// Start(ContainerId),
// Stop(ContainerId),
// Resume(ContainerId),
Update,
}
+1 -15
View File
@@ -10,10 +10,7 @@ use futures_util::StreamExt;
use parking_lot::Mutex;
use std::{
collections::HashMap,
sync::{
atomic::{AtomicBool, AtomicUsize},
Arc,
},
sync::{atomic::AtomicUsize, Arc},
};
use tokio::{
sync::mpsc::{Receiver, Sender},
@@ -62,7 +59,6 @@ pub struct DockerData {
binate: Binate,
docker: Arc<Docker>,
gui_state: Arc<Mutex<GuiState>>,
is_running: Arc<AtomicBool>,
init: Option<Arc<AtomicUsize>>,
receiver: Receiver<DockerMessage>,
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
@@ -410,14 +406,6 @@ impl DockerData {
docker_tx.send(Arc::clone(&self.docker)).ok();
}
DockerMessage::Update => self.update_everything().await,
DockerMessage::Quit => {
self.spawns
.lock()
.values()
.for_each(tokio::task::JoinHandle::abort);
self.is_running
.store(false, std::sync::atomic::Ordering::SeqCst);
}
}
}
}
@@ -443,7 +431,6 @@ impl DockerData {
docker_rx: Receiver<DockerMessage>,
docker_tx: Sender<DockerMessage>,
gui_state: Arc<Mutex<GuiState>>,
is_running: Arc<AtomicBool>,
) {
let args = app_data.lock().args.clone();
if app_data.lock().get_error().is_none() {
@@ -454,7 +441,6 @@ impl DockerData {
docker: Arc::new(docker),
gui_state,
init: Some(Arc::new(AtomicUsize::new(0))),
is_running,
receiver: docker_rx,
spawns: Arc::new(Mutex::new(HashMap::new())),
};
+4 -10
View File
@@ -1,10 +1,7 @@
use std::{
fs::OpenOptions,
io::{BufWriter, Write},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
sync::{atomic::AtomicBool, Arc},
time::SystemTime,
};
@@ -84,9 +81,6 @@ impl InputHandler {
}
}
}
if !self.is_running.load(Ordering::SeqCst) {
break;
}
}
}
@@ -97,12 +91,12 @@ impl InputHandler {
/// Send a quit message to docker, to abort all spawns, if an error is returned, set is_running to false here instead
/// If gui_status is Error or Init, then just set the is_running to false immediately, for a quicker exit
async fn quit(&self) {
fn quit(&self) {
let error_init = self
.gui_state
.lock()
.status_contains(&[Status::Error, Status::Init]);
if error_init || self.docker_tx.send(DockerMessage::Quit).await.is_err() {
if !error_init {
self.is_running
.store(false, std::sync::atomic::Ordering::SeqCst);
}
@@ -466,7 +460,7 @@ impl InputHandler {
let is_q = || key_code == KeyCode::Char('q') || key_code == KeyCode::Char('Q');
if key_modifier == KeyModifiers::CONTROL && is_c() || is_q() && !contains_filter {
// Always just quit on Ctrl + c/C or q/Q, unless in FIlter status active
self.quit().await;
self.quit();
}
if contains_error {
+2 -12
View File
@@ -52,7 +52,6 @@ async fn docker_init(
docker_rx: Receiver<DockerMessage>,
docker_tx: Sender<DockerMessage>,
gui_state: &Arc<Mutex<GuiState>>,
is_running: &Arc<AtomicBool>,
host: Option<String>,
) {
let connection = host.map_or_else(Docker::connect_with_socket_defaults, |host| {
@@ -63,10 +62,9 @@ async fn docker_init(
if docker.ping().await.is_ok() {
let app_data = Arc::clone(app_data);
let gui_state = Arc::clone(gui_state);
let is_running = Arc::clone(is_running);
tokio::spawn(DockerData::init(
app_data, docker, docker_rx, docker_tx, gui_state, is_running,
app_data, docker, docker_rx, docker_tx, gui_state,
));
} else {
app_data
@@ -118,15 +116,7 @@ async fn main() {
let is_running = Arc::new(AtomicBool::new(true));
let (docker_tx, docker_rx) = tokio::sync::mpsc::channel(32);
docker_init(
&app_data,
docker_rx,
docker_tx.clone(),
&gui_state,
&is_running,
host,
)
.await;
docker_init(&app_data, docker_rx, docker_tx.clone(), &gui_state, host).await;
if args.gui {
let (input_tx, input_rx) = tokio::sync::mpsc::channel(32);