mirror of
https://github.com/MingweiSamuel/Riven.git
synced 2025-01-24 09:47:26 -08:00
simplify metrics into async fn
This commit is contained in:
parent
9718cebcfc
commit
318ac138c5
1 changed files with 6 additions and 12 deletions
|
@ -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<Fut>(
|
||||
future: Fut,
|
||||
operation: &'static str,
|
||||
route: &'static str,
|
||||
) -> impl Future<Output = Fut::Output>
|
||||
pub async fn timed<Fut>(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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue