require clone bound inner error type rather than Arcifying it ourselves

This commit is contained in:
Jane Lusby 2020-06-17 17:00:19 -07:00 committed by Deirdre Connolly
parent 9db936923b
commit faf36f5c04
3 changed files with 19 additions and 14 deletions

View File

@ -40,7 +40,7 @@ where
S::Future: Send, S::Future: Send,
S::Error: Clone + Into<E> + Send + Sync, S::Error: Clone + Into<E> + Send + Sync,
Request: Send + 'static, Request: Send + 'static,
E: Clone + Send + 'static, E: Send + 'static,
crate::error::Closed: Into<E>, crate::error::Closed: Into<E>,
{ {
type Service = Batch<S, Request, E>; type Service = Batch<S, Request, E>;

View File

@ -22,14 +22,14 @@ where
T: Service<BatchControl<Request>>, T: Service<BatchControl<Request>>,
{ {
tx: mpsc::Sender<Message<Request, T::Future, T::Error>>, tx: mpsc::Sender<Message<Request, T::Future, T::Error>>,
handle: Handle<E>, handle: Handle<T::Error, E>,
_error_type: PhantomData<E>, _error_type: PhantomData<E>,
} }
impl<T, Request, E> Batch<T, Request, E> impl<T, Request, E> Batch<T, Request, E>
where where
T: Service<BatchControl<Request>>, T: Service<BatchControl<Request>>,
T::Error: Into<E>, T::Error: Into<E> + Clone,
E: Send + 'static, E: Send + 'static,
crate::error::Closed: Into<E>, crate::error::Closed: Into<E>,
// crate::error::Closed: Into<<Self as Service<Request>>::Error> + Send + Sync + 'static, // crate::error::Closed: Into<<Self as Service<Request>>::Error> + Send + Sync + 'static,
@ -72,7 +72,7 @@ impl<T, Request, E> Service<Request> for Batch<T, Request, E>
where where
T: Service<BatchControl<Request>>, T: Service<BatchControl<Request>>,
crate::error::Closed: Into<E>, crate::error::Closed: Into<E>,
T::Error: Into<E>, T::Error: Into<E> + Clone,
E: Send + 'static, E: Send + 'static,
{ {
type Response = T::Response; type Response = T::Response;

View File

@ -34,7 +34,7 @@ where
rx: mpsc::Receiver<Message<Request, T::Future, T::Error>>, rx: mpsc::Receiver<Message<Request, T::Future, T::Error>>,
service: T, service: T,
failed: Option<T::Error>, failed: Option<T::Error>,
handle: Handle<E>, handle: Handle<T::Error, E>,
max_items: usize, max_items: usize,
max_latency: std::time::Duration, max_latency: std::time::Duration,
_error_type: PhantomData<E>, _error_type: PhantomData<E>,
@ -42,8 +42,9 @@ where
/// Get the error out /// Get the error out
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Handle<E> { pub(crate) struct Handle<E, E2> {
inner: Arc<Mutex<Option<E>>>, inner: Arc<Mutex<Option<E>>>,
_e: PhantomData<E2>,
} }
impl<T, Request, E> Worker<T, Request, E> impl<T, Request, E> Worker<T, Request, E>
@ -56,9 +57,10 @@ where
rx: mpsc::Receiver<Message<Request, T::Future, T::Error>>, rx: mpsc::Receiver<Message<Request, T::Future, T::Error>>,
max_items: usize, max_items: usize,
max_latency: std::time::Duration, max_latency: std::time::Duration,
) -> (Handle<E>, Worker<T, Request, E>) { ) -> (Handle<T::Error, E>, Worker<T, Request, E>) {
let handle = Handle { let handle = Handle {
inner: Arc::new(Mutex::new(None)), inner: Arc::new(Mutex::new(None)),
_e: PhantomData,
}; };
let worker = Worker { let worker = Worker {
@ -190,7 +192,7 @@ where
return; return;
} }
*inner = Some(error.clone().into()); *inner = Some(error.clone());
drop(inner); drop(inner);
self.rx.close(); self.rx.close();
@ -203,23 +205,26 @@ where
} }
} }
impl<E> Handle<E> impl<E, E2> Handle<E, E2>
where where
crate::error::Closed: Into<E>, E: Clone + Into<E2>,
crate::error::Closed: Into<E2>,
{ {
pub(crate) fn get_error_on_closed(&self) -> E { pub(crate) fn get_error_on_closed(&self) -> E2 {
self.inner self.inner
.lock() .lock()
.unwrap() .unwrap()
.take() .clone()
.map(Into::into)
.unwrap_or_else(|| Closed::new().into()) .unwrap_or_else(|| Closed::new().into())
} }
} }
impl<E> Clone for Handle<E> { impl<E, E2> Clone for Handle<E, E2> {
fn clone(&self) -> Handle<E> { fn clone(&self) -> Handle<E, E2> {
Handle { Handle {
inner: self.inner.clone(), inner: self.inner.clone(),
_e: PhantomData,
} }
} }
} }