1 //! A thin wrapper around `ThreadPool` to make sure that we join all things
3 use crossbeam_channel::Sender;
5 pub(crate) struct TaskPool<T> {
7 inner: threadpool::ThreadPool,
11 pub(crate) fn new(sender: Sender<T>) -> TaskPool<T> {
12 const STACK_SIZE: usize = 8 * 1024 * 1024;
14 let inner = threadpool::Builder::new()
15 .thread_name("Worker".into())
16 .thread_stack_size(STACK_SIZE)
18 TaskPool { sender, inner }
21 pub(crate) fn spawn<F>(&mut self, task: F)
23 F: FnOnce() -> T + Send + 'static,
27 let sender = self.sender.clone();
28 move || sender.send(task()).unwrap()
32 pub(crate) fn spawn_with_sender<F>(&mut self, task: F)
34 F: FnOnce(Sender<T>) + Send + 'static,
38 let sender = self.sender.clone();
43 pub(crate) fn len(&self) -> usize {
44 self.inner.queued_count()
48 impl<T> Drop for TaskPool<T> {