Skip to main content

task_callbacks

Function task_callbacks 

Source
pub unsafe fn task_callbacks<FBefore, FEnter, FExit, FAfter>(
    f_before: FBefore,
    f_enter: FEnter,
    f_exit: FExit,
    f_after: FAfter,
)
where FBefore: Fn() -> Option<*const ()> + 'static + Sync, FEnter: Fn(*const ()) -> *const () + 'static + Sync, FExit: Fn(*const ()) + 'static + Sync, FAfter: Fn(*const ()) + 'static + Sync,
Expand description

Installs process-wide callbacks for instrumenting spawned tasks.

Callbacks apply when crate::spawn, crate::spawn_detached, crate::rt::spawn, or crate::rt::spawn_detached wraps a future, not retroactively to existing tasks. Direct crate::rt::Runtime spawning methods do not apply them.

  • f_before runs synchronously when the future is wrapped. Returning None disables the remaining callbacks for that future.
  • f_enter receives the task’s pointer before each poll and returns a pointer representing the previous context.
  • f_exit receives that previous-context pointer after the poll, including when polling unwinds.
  • f_after receives the task’s original pointer when its callback state is dropped, including cancellation before the first poll.

Registration is permanent and first-wins. Does nothing if callbacks were already installed; use task_opt_callbacks to observe registration success.

§Safety

Pointers are opaque to the runtime. The caller must keep the state returned by f_before valid until f_after, and the state returned by f_enter valid until its matching f_exit. Callbacks must safely handle concurrent use by different runtime threads and any nested task activity they trigger.