pub fn spawn_timed<F>(
future: F,
counter: Option<Counter>,
) -> JoinHandle<F::Output> ⓘExpand description
Spawns future on the current tokio runtime, attaching CPU-time
accounting when counter is Some. When None, the future is
spawned as-is with no per-poll overhead.
Equivalent to:
ⓘ
// Some(counter):
crate::spawn_in_current_span(future.cpu_timed(counter))
// None:
crate::spawn_in_current_span(future)Use this when spawning background tasks (e.g. a transform’s housekeeping
loop) whose CPU usage should be attributed back to a component. Wrap the
future with [tracing::Instrument] (or similar adapters) before passing
it in if you want those adapters’ per-poll work included in the CPU-time
measurement.
The current tracing span is attached to the spawned task.