2019-08-15 13:09:02 -07:00
|
|
|
use super::worker::Worker;
|
|
|
|
|
|
2018-03-28 01:56:21 +03:00
|
|
|
use std::fmt;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub(crate) struct Callback {
|
2019-07-16 14:29:35 -04:00
|
|
|
f: Arc<dyn Fn(&Worker) + Send + Sync>,
|
2018-03-28 01:56:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Callback {
|
2019-08-11 04:28:52 +09:00
|
|
|
pub(crate) fn new<F>(f: F) -> Self
|
2019-02-21 11:56:15 -08:00
|
|
|
where
|
2019-07-16 14:29:35 -04:00
|
|
|
F: Fn(&Worker) + Send + Sync + 'static,
|
2018-03-28 01:56:21 +03:00
|
|
|
{
|
|
|
|
|
Callback { f: Arc::new(f) }
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-11 04:28:52 +09:00
|
|
|
pub(crate) fn call(&self, worker: &Worker) {
|
2019-07-16 14:29:35 -04:00
|
|
|
(self.f)(worker)
|
2018-03-28 01:56:21 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
}
|