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 TaskPool { sender, inner: threadpool::ThreadPool::default() }
15 pub(crate) fn spawn<F>(&mut self, task: F)
17 F: FnOnce() -> T + Send + 'static,
21 let sender = self.sender.clone();
22 move || sender.send(task()).unwrap()
26 pub(crate) fn spawn_with_sender<F>(&mut self, task: F)
28 F: FnOnce(Sender<T>) + Send + 'static,
32 let sender = self.sender.clone();
37 pub(crate) fn len(&self) -> usize {
38 self.inner.queued_count()
42 impl<T> Drop for TaskPool<T> {