From 318ac138c5b967641cf1a7e22561d655f30c20b6 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Mon, 13 Jan 2025 11:31:36 -0800 Subject: [PATCH] simplify metrics into async fn --- riven/src/metrics.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/riven/src/metrics.rs b/riven/src/metrics.rs index 5cdd097..64bff93 100644 --- a/riven/src/metrics.rs +++ b/riven/src/metrics.rs @@ -3,19 +3,13 @@ use std::future::Future; use crate::time::Instant; /// Returns a wrapped future that records the time it takes to complete the future as a histogram metric. -pub fn timed( - future: Fut, - operation: &'static str, - route: &'static str, -) -> impl Future +pub async fn timed(future: Fut, operation: &'static str, route: &'static str) -> Fut::Output where Fut: Future, { - async move { - let start = Instant::now(); - let out = future.await; - metrics::histogram!("riot_api", "operation" => operation, "route" => route) - .record(start.elapsed()); - out - } + let start = Instant::now(); + let out = future.await; + metrics::histogram!("riot_api", "operation" => operation, "route" => route) + .record(start.elapsed()); + out }