pub trait BaseThreadPool {
fn execute<F>(&self, job: F)
where
F: FnOnce() + Send + 'static;
}
#[derive(Debug, Default)]
pub struct SimpleThreadPool(pub threadpool::ThreadPool);
impl BaseThreadPool for SimpleThreadPool {
fn execute<F>(&self, job: F)
where
F: FnOnce() + Send + 'static,
{
self.0.execute(job)
}
}
#[cfg(test)]
mod tests {
use super::{BaseThreadPool, SimpleThreadPool};
use std::sync::mpsc;
use std::time::Duration;
#[test]
fn test_execute_runs_submitted_job() {
let pool = SimpleThreadPool::default();
let (sender, receiver) = mpsc::channel();
pool.execute(move || sender.send(()).unwrap());
assert_eq!(receiver.recv_timeout(Duration::from_secs(1)), Ok(()));
}
}