2019-05-14 10:27:36 -07:00
|
|
|
use crate::worker::Worker;
|
2018-03-28 01:56:21 +03:00
|
|
|
use std::fmt;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use tokio_executor::Enter;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub(crate) struct Callback {
|
2019-05-14 10:27:36 -07:00
|
|
|
f: Arc<dyn Fn(&Worker, &mut Enter) + Send + Sync>,
|
2018-03-28 01:56:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Callback {
|
|
|
|
|
pub fn new<F>(f: F) -> Self
|
2019-02-21 11:56:15 -08:00
|
|
|
where
|
|
|
|
|
F: Fn(&Worker, &mut Enter) + Send + Sync + 'static,
|
2018-03-28 01:56:21 +03:00
|
|
|
{
|
|
|
|
|
Callback { f: Arc::new(f) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn call(&self, worker: &Worker, enter: &mut Enter) {
|
|
|
|
|
(self.f)(worker, enter)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Debug for Callback {
|
2019-05-14 10:27:36 -07:00
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-03-28 01:56:21 +03:00
|
|
|
write!(fmt, "Fn")
|
|
|
|
|
}
|
|
|
|
|
}
|