pub unsafe fn task_callbacks<FBefore, FEnter, FExit, FAfter>(
f_before: FBefore,
f_enter: FEnter,
f_exit: FExit,
f_after: FAfter,
)Expand description
Installs process-wide callbacks for instrumenting spawned tasks.
Callbacks apply when crate::spawn, crate::spawn_detached,
spawn_sendable, 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_beforeruns synchronously when the future is wrapped. ReturningNonedisables the remaining callbacks for that future.f_enterreceives the task’s pointer before each poll and returns a pointer representing the previous context.f_exitreceives that previous-context pointer after the poll, including when polling unwinds.f_afterreceives 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.