Sha256: 7afda370b78deba9bc073274d00869a0d32e544a43935d1ad9f12a0b2397f1fd
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
use std::marker::PhantomData; impl TaskHooks { pub(crate) fn spawn(&self, meta: &TaskMeta<'_>) { if let Some(f) = self.task_spawn_callback.as_ref() { f(meta) } } } #[derive(Clone)] pub(crate) struct TaskHooks { pub(crate) task_spawn_callback: Option<TaskCallback>, pub(crate) task_terminate_callback: Option<TaskCallback>, } /// Task metadata supplied to user-provided hooks for task events. /// /// **Note**: This is an [unstable API][unstable]. The public API of this type /// may break in 1.x releases. See [the documentation on unstable /// features][unstable] for details. /// /// [unstable]: crate#unstable-features #[allow(missing_debug_implementations)] #[cfg_attr(not(tokio_unstable), allow(unreachable_pub))] pub struct TaskMeta<'a> { /// The opaque ID of the task. pub(crate) id: super::task::Id, pub(crate) _phantom: PhantomData<&'a ()>, } impl<'a> TaskMeta<'a> { /// Return the opaque ID of the task. #[cfg_attr(not(tokio_unstable), allow(unreachable_pub, dead_code))] pub fn id(&self) -> super::task::Id { self.id } } /// Runs on specific task-related events pub(crate) type TaskCallback = std::sync::Arc<dyn Fn(&TaskMeta<'_>) + Send + Sync>;
Version data entries
3 entries across 3 versions & 1 rubygems