1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::{
    any::Any,
    collections::HashMap,
    sync::{atomic::AtomicUsize, mpsc, Arc, Mutex},
    thread,
    time::Duration,
};

pub mod error;
pub mod threadpool;

pub struct Expectation<T> {
    result_receiver: Option<mpsc::Receiver<Result<T, Box<dyn Any + Send>>>>,
}

pub struct ThreadPool {
    current_id: AtomicUsize,
    workers: Arc<Mutex<HashMap<usize, threadpool::Worker>>>,
    worker_count: Arc<AtomicUsize>,
    working_count: Arc<AtomicUsize>,
    task_sender: Option<mpsc::Sender<threadpool::Job>>,
    task_receiver: Arc<Mutex<mpsc::Receiver<threadpool::Job>>>,
    worker_status_sender: Option<mpsc::Sender<(usize, threadpool::WorkerStatus)>>,
    m_thread: Option<thread::JoinHandle<()>>,
    max_size: usize,
    policy: threadpool::ExceedLimitPolicy,
    keep_alive_time: Option<Duration>,
}