exp backoff and theads handling

This commit is contained in:
TIBERGHIEN corentin
2026-01-20 01:10:09 +01:00
parent 08518892f2
commit dacedd1ceb
9 changed files with 469 additions and 331 deletions

View File

@@ -0,0 +1,35 @@
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
use std::thread::JoinHandle;
pub enum WorkerType {
MSGRECEPTION,
MSGSENDER,
PING,
MSGRETRY,
}
pub struct Worker {
thread: Option<JoinHandle<()>>,
stop: Arc<AtomicBool>,
workertype: WorkerType,
}
impl Worker {
pub fn spawn(thread: JoinHandle<()>, workertype: WorkerType) -> Self {
Worker {
stop: Arc::new(AtomicBool::new(false)),
thread: Some(thread),
workertype,
}
}
pub fn stop(mut self) {
self.stop.store(true, Ordering::Relaxed);
if let Some(h) = self.thread.take() {
let _ = h.join();
}
}
}