Files
tokio/tokio-executor/src/threadpool/callback.rs
T

29 lines
530 B
Rust
Raw Normal View History

use super::worker::Worker;
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>,
}
impl Callback {
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,
{
Callback { f: Arc::new(f) }
}
pub(crate) fn call(&self, worker: &Worker) {
2019-07-16 14:29:35 -04:00
(self.f)(worker)
}
}
impl fmt::Debug for Callback {
2019-05-14 10:27:36 -07:00
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "Fn")
}
}