mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-15 00:00:15 +02:00
29 lines
592 B
Rust
29 lines
592 B
Rust
use crate::worker::Worker;
|
|
use std::fmt;
|
|
use std::sync::Arc;
|
|
use tokio_executor::Enter;
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct Callback {
|
|
f: Arc<dyn Fn(&Worker, &mut Enter) + Send + Sync>,
|
|
}
|
|
|
|
impl Callback {
|
|
pub fn new<F>(f: F) -> Self
|
|
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 {
|
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(fmt, "Fn")
|
|
}
|
|
}
|