src/tools/parallel_handler.rs: remove unnecessary Sync bound

This commit is contained in:
Dietmar Maurer 2020-09-26 16:13:44 +02:00
parent 42fd40a124
commit 55bee04856
1 changed files with 7 additions and 5 deletions

View File

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