diff --git a/src/tools/parallel_handler.rs b/src/tools/parallel_handler.rs index f0274afe..bc807700 100644 --- a/src/tools/parallel_handler.rs +++ b/src/tools/parallel_handler.rs @@ -1,7 +1,7 @@ use std::thread::{JoinHandle}; use std::sync::{Arc, Mutex}; use crossbeam_channel::{bounded, Sender}; -use anyhow::{format_err, Error}; +use anyhow::{bail, format_err, Error}; /// A handle to send data toƶ the worker thread (implements clone) pub struct SendHandle { @@ -9,7 +9,7 @@ pub struct SendHandle { abort: Arc>>, } -impl SendHandle { +impl SendHandle { /// Returns the first error happened, if any pub fn check_abort(&self) -> Result<(), Error> { @@ -23,8 +23,10 @@ impl SendHandle { /// Send data to the worker threads pub fn send(&self, input: I) -> Result<(), Error> { self.check_abort()?; - self.input.send(input)?; - Ok(()) + match self.input.send(input) { + Ok(()) => Ok(()), + Err(_) => bail!("send failed - channel closed"), + } } } @@ -49,7 +51,7 @@ impl Clone for SendHandle { } } -impl <'a, I: Send + Sync + 'static> ParallelHandler<'a, I> { +impl <'a, I: Send + 'static> ParallelHandler<'a, I> { /// Create a new thread pool, each thread processing incoming data /// with 'handler_fn'.