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

29 lines
592 B
Rust
Raw Normal View History

2019-05-14 10:27:36 -07:00
use crate::worker::Worker;
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>,
}
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,
{
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 {
write!(fmt, "Fn")
}
}