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;
|
use crate::time::Instant;
|
||||||
|
|
||||||
/// Returns a wrapped future that records the time it takes to complete the future as a histogram metric.
|
/// Returns a wrapped future that records the time it takes to complete the future as a histogram metric.
|
||||||
pub fn timed<Fut>(
|
pub async fn timed<Fut>(future: Fut, operation: &'static str, route: &'static str) -> Fut::Output
|
||||||
future: Fut,
|
|
||||||
operation: &'static str,
|
|
||||||
route: &'static str,
|
|
||||||
) -> impl Future<Output = Fut::Output>
|
|
||||||
where
|
where
|
||||||
Fut: Future,
|
Fut: Future,
|
||||||
{
|
{
|
||||||
async move {
|
let start = Instant::now();
|
||||||
let start = Instant::now();
|
let out = future.await;
|
||||||
let out = future.await;
|
metrics::histogram!("riot_api", "operation" => operation, "route" => route)
|
||||||
metrics::histogram!("riot_api", "operation" => operation, "route" => route)
|
.record(start.elapsed());
|
||||||
.record(start.elapsed());
|
out
|
||||||
out
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue