Skip to main content

tokio_threadpool/park/
boxed.rs

1use tokio_executor::park::{Park, Unpark};
2
3use std::error::Error;
4use std::time::Duration;
5
6pub(crate) type BoxPark = Box<dyn Park<Unpark = BoxUnpark, Error = ()> + Send>;
7pub(crate) type BoxUnpark = Box<dyn Unpark>;
8
9pub(crate) struct BoxedPark<T>(T);
10
11impl<T> BoxedPark<T> {
12    pub fn new(inner: T) -> Self {
13        BoxedPark(inner)
14    }
15}
16
17impl<T: Park + Send> Park for BoxedPark<T>
18where
19    T::Error: Error,
20{
21    type Unpark = BoxUnpark;
22    type Error = ();
23
24    fn unpark(&self) -> Self::Unpark {
25        Box::new(self.0.unpark())
26    }
27
28    fn park(&mut self) -> Result<(), Self::Error> {
29        self.0.park().map_err(|e| {
30            warn!(
31                "calling `park` on worker thread errored -- shutting down thread: {}",
32                e
33            );
34        })
35    }
36
37    fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> {
38        self.0.park_timeout(duration).map_err(|e| {
39            warn!(
40                "calling `park` on worker thread errored -- shutting down thread: {}",
41                e
42            );
43        })
44    }
45}