pi_async_executor/
hooks.rs1use pi_async_task::{
3 definitions::{RunOutcome, TaskId, TaskSnapshot},
4 TaskRegistration,
5};
6
7pub struct TaskInfo<'a> {
9 registration: &'a TaskRegistration,
10}
11impl<'a> TaskInfo<'a> {
12 pub(crate) fn new(registration: &'a TaskRegistration) -> Self {
13 Self { registration }
14 }
15 pub fn id(&self) -> TaskId {
16 self.registration.snapshot().id
17 }
18 pub fn snapshot(&self) -> TaskSnapshot {
19 self.registration.snapshot()
20 }
21 pub fn metadata<M: Send + Sync + 'static>(&self) -> Option<&M> {
23 self.registration.metadata::<M>()
24 }
25}
26#[derive(Clone, Copy, Debug, Eq, PartialEq)]
28pub enum TaskAction {
29 Poll,
31 Defer,
33 Cancel,
35}
36#[derive(Clone, Copy, Debug, Eq, PartialEq)]
37pub enum ExecutorEvent {
40 BeforePoll,
42 AfterRun(RunOutcome),
44}
45pub trait ExecutorHooks {
48 fn on_event(&mut self, event: ExecutorEvent, task: &TaskInfo<'_>) {
50 hook_event_default_inner(event, task)
51 }
52 fn before_poll(&mut self, task: &TaskInfo<'_>) -> TaskAction {
55 hook_control_default_inner(task)
56 }
57}
58#[derive(Default, Clone, Copy, Debug)]
60pub struct NoHooks;
61impl ExecutorHooks for NoHooks {}
62include!("hooks_inner.rs");