startup: Add spinloop until deamon is ready

This commit is contained in:
DashieTM 2024-06-05 00:43:23 +02:00
parent 918bf9c70a
commit dcc9de9230
4 changed files with 23 additions and 16 deletions

View file

@ -24,7 +24,11 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[tokio::main]
async fn main() {
tokio::task::spawn(daemon_check());
let ready = Arc::new(AtomicBool::new(false));
tokio::task::spawn(daemon_check(ready.clone()));
while !ready.load(std::sync::atomic::Ordering::SeqCst) {
hint::spin_loop();
}
gio::resources_register_include!("src.templates.gresource")
.expect("Failed to register resources.");
gio::resources_register_include!("src.icons.gresource").expect("Failed to register resources.");
@ -67,19 +71,15 @@ fn shutdown(_: &Application) {
});
}
async fn daemon_check() {
let handle = thread::spawn(|| {
async fn daemon_check(ready: Arc<AtomicBool>) {
let handle = thread::spawn(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(100));
let res: Result<(), Error> = proxy.method_call(BASE, "RegisterClient", ("ReSet",));
res
});
let ready = Arc::new(AtomicBool::new(false));
let res = handle.join();
if res.unwrap().is_err() {
run_daemon(Some(ready.clone())).await;
}
while !ready.load(std::sync::atomic::Ordering::SeqCst) {
hint::spin_loop();
run_daemon(Some(ready)).await;
}
}

View file

@ -4,15 +4,22 @@ async fn test_plugins() {
use crate::daemon_check;
use re_set_lib::utils::plugin::plugin_tests;
use re_set_lib::utils::plugin_setup::FRONTEND_PLUGINS;
use std::thread;
use std::time::Duration;
tokio::task::spawn(daemon_check());
thread::sleep(Duration::from_millis(2000));
use std::hint;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
let ready = Arc::new(AtomicBool::new(false));
let rc = tokio::runtime::Runtime::new().expect("Failed to create runtime");
rc.spawn(daemon_check(ready.clone()));
while !ready.load(std::sync::atomic::Ordering::SeqCst) {
hint::spin_loop();
}
unsafe {
println!("pang");
for plugin in FRONTEND_PLUGINS.iter() {
let name = (plugin.frontend_name)();
let tests = (plugin.frontend_tests)();
plugin_tests(name, tests);
}
}
rc.shutdown_background();
}