fralalonde/dipstick

Purpose of Instant in the Observe's Fn(Instant) callback

mixalturek opened this issue · 1 comments

What is purpose of Instant parameter in the Observe's callback function? No example uses it, the closure is always defined as |_|. I found Instant::now() is passed there in Scheduler, but I'm still curious about expected use cases. A short note in observe()'s doc would be great.

/// Schedule a recurring task
pub trait Observe {
    /// Provide a source for a metric's values.
    fn observe<F>(
        &self,
        metric: impl Deref<Target = InputMetric>,
        operation: F,
    ) -> ObserveWhen<Self, F>
    where
        F: Fn(Instant) -> MetricValue + Send + Sync + 'static,
        Self: Sized;
}

The goal is to make observers be FnMut eventually so that they could have state and use the instant compare / compute the time between each observation if they so wish. The FnMut thing didnt pan out but I thought at least the API would not change incompatibly if I introduced it later with the parameter already there. This relies on the assertion that querying the time multiple times can be much slower and imprecise than querying it once and then pass it around. The instant can also be copied to an async queue if need be, preventing collection thread vs processing thread time discrepancies.