use std::thread;
use std::sync::mpsc;
use std::sync::Arc;
use std::sync::Mutex;
use crate::actor::Actor;
pub struct Thread {
id: usize,
thread: thread::JoinHandle<Arc<Mutex<mpsc::Receiver<Actor>>>>
}
impl Thread {
pub fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Actor>>>) -> Thread{
let thread = thread::spawn(move || {
loop {
let actor = receiver.lock().expect("Thread lock panick").recv().unwrap();
println!("Thread {} got a job to do; executing ...", id);
actor.call_box();
}
});
Thread {
id,
thread
}
}
}