diff --git a/src/worker/worker.rs b/src/worker/worker.rs index 3a4f516..795aefe 100644 --- a/src/worker/worker.rs +++ b/src/worker/worker.rs @@ -7,6 +7,9 @@ use super::handler::Handler; use crate::error::HandlerError; use crate::model::*; +// Queue is a simple queue data structure. +// +// It is protected by a mutex and avoid to be CPU consuming with `not_empty` condvar. pub struct Queue { content: Mutex>, not_empty: Condvar, @@ -30,6 +33,7 @@ pub enum WorkerStatus { Stopped, } +// Worker holds the computation in thread with a status. struct Worker { id: u32, manager: String, @@ -55,6 +59,9 @@ impl Worker { } } +// Manager is a pool of workers and holds a queue containing `Job` to run. +// +// TODO: to handle more message, replace the trait with a `Message` trait. pub struct Manager { name: String, workers: Vec>>, @@ -111,6 +118,7 @@ impl Manager { } } + // subscribe subscribes to a `Receiver` channel. pub fn subscribe(&self, receiver: Receiver) { let queue = self.queue.clone(); thread::spawn(move || loop {