Skip to main content

spawn_metered

Function spawn_metered 

Source
pub async fn spawn_metered<T, G, F>(
    operation: &'static str,
    guard: G,
    f: F,
) -> Result<T>
where T: Send + 'static, G: Send + 'static, F: Future<Output = Result<T>> + Send + 'static,
Expand description

Spawns a future on a dedicated task with panic isolation and timing metrics.

The guard is moved into the spawned task and dropped after the future completes, ensuring any resource it represents (e.g. a concurrency permit) outlives the operation.

Emits service.task.start (counter) before spawning and service.task.duration (distribution) when the task completes, both tagged with the given operation name. The duration tag includes an outcome of "success" or "error".