LCOV - code coverage report
Current view: top level - libs/metrics/src - metric_vec_duration.rs (source / functions) Coverage Total Hit
Test: 32f4a56327bc9da697706839ed4836b2a00a408f.info Lines: 100.0 % 15 15
Test Date: 2024-02-07 07:37:29 Functions: 50.0 % 4 2

            Line data    Source code
       1              : //! Helpers for observing duration on `HistogramVec` / `CounterVec` / `GaugeVec` / `MetricVec<T>`.
       2              : 
       3              : use std::{future::Future, time::Instant};
       4              : 
       5              : pub trait DurationResultObserver {
       6              :     fn observe_result<T, E>(&self, res: &Result<T, E>, duration: std::time::Duration);
       7              : }
       8              : 
       9          630 : pub async fn observe_async_block_duration_by_result<
      10          630 :     T,
      11          630 :     E,
      12          630 :     F: Future<Output = Result<T, E>>,
      13          630 :     O: DurationResultObserver,
      14          630 : >(
      15          630 :     observer: &O,
      16          630 :     block: F,
      17          630 : ) -> Result<T, E> {
      18          630 :     let start = Instant::now();
      19        46070 :     let result = block.await;
      20          630 :     let duration = start.elapsed();
      21          630 :     observer.observe_result(&result, duration);
      22          630 :     result
      23          630 : }
        

Generated by: LCOV version 2.1-beta