start documentation
This commit is contained in:
parent
a1900c7858
commit
452cfc81b9
@ -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<T> {
|
||||
content: Mutex<VecDeque<T>>,
|
||||
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<T: Runner> {
|
||||
name: String,
|
||||
workers: Vec<Arc<Mutex<Worker>>>,
|
||||
@ -111,6 +118,7 @@ impl<T: Runner + Send + 'static> Manager<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// subscribe subscribes to a `Receiver` channel.
|
||||
pub fn subscribe(&self, receiver: Receiver<T>) {
|
||||
let queue = self.queue.clone();
|
||||
thread::spawn(move || loop {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user