/// Spawns an async cycle read thread that reports metrics.
///
/// This function returns three objects callers may interact with:
///  * `cmd_tx`: send the unit value `()` via this channel to ask the
///    background thread to terminate, e.g. `cmd_tx.send(())?`
///  * `metric_rx`: read metrics are periodically sent here
///  * `handle`: a thread JoinHandle
///
/// This takes ownership of the `Metriful` instance for as long as the
/// background thread is alive. The original owned [`Metriful`] is returned
/// via `.join()` on the returned `JoinHandle`. Send the unit value `()` via
/// `cmd_tx` (e.g. `cmd_tx.send(())?`) to ask the thread to terminate before
/// attempting to join it to avoid a deadlock.
///
/// If an error occurs, it will be sent via `metric_rx` and the thread will
/// terminate.
Spawns an async cycle read thread that reports metrics.
This function returns three objects callers may interact with:
`cmd_tx`: send the unit value `()` via this channel to ask the
background thread to terminate, e.g.

This takes ownership of the `Metriful` instance for as long as the
background thread is alive.

If an error occurs, it will be sent via `metric_rx` and the thread will
terminate.
Spawns an async cycle read thread that reports metrics . This function returns three objects callers may interact with : ` cmd_tx ` : send the unit value ` () ` via this channel to ask the background thread to terminate e . g . This takes ownership of the ` Metriful ` instance for as long as the background thread is alive . If an error occurs it will be sent via ` metric_rx ` and the thread will terminate .
pub fn async_cycle_read_timeout<U>(
    mut self,
    metric: Metric<U>,
    cycle_period: CyclePeriod,
    timeout: Option<Duration>,
  ) -> (Sender<()>, Receiver<Result<UnitValue<U>>>, JoinHandle<Metriful>)
  where
    U: MetrifulUnit + 'static
  {
    let (cmd_tx, cmd_rx) = channel();
    let (metric_tx, metric_rx) = channel();
    let handle = thread::spawn(move || {
      let iter = self.cycle_read_iter_timeout(metric, cycle_period, timeout);
      for metric in iter {
        if cmd_rx.try_recv().is_ok() {
          trace!("Metriful::async_cycle_read_timeout(): break");
          break;
        }
        let metric = match metric {
          Ok(m) => m,
          Err(e) => {
            metric_tx.send(Err(e)).ok();
            break;
          }
        };
        match metric_tx.send(Ok(metric)) {
          Ok(_) => (),
          Err(_e) => {
            // channel is dead, just quit
            break;
          }
        }
      }
      self
    });
    (cmd_tx, metric_rx, handle)
  }
pub fn async_cycle_read_timeout < U > ( mut self , metric : Metric < U > , cycle_period : CyclePeriod , timeout : Option < Duration > , ) -> ( Sender < ( ) > , Receiver < Result < UnitValue < U > > > , JoinHandle < Metriful > ) where U : MetrifulUnit + ' static { let ( cmd_tx , cmd_rx ) = channel ( ) ; let ( metric_tx , metric_rx ) = channel ( ) ; let handle = thread :: spawn ( move | | { let iter = self . cycle_read_iter_timeout ( metric , cycle_period , timeout ) ; for metric in iter { if cmd_rx . try_recv ( ) . is_ok ( ) { trace ! ( " " ) ; break ; } let metric = match metric { Ok ( m ) => m , Err ( e ) => { metric_tx . send ( Err ( e ) ) . ok ( ) ; break ; } } ; match metric_tx . send ( Ok ( metric ) ) { Ok ( _ ) => ( ) , Err ( _e ) => { // channel is dead, just quit break ; } } } self } ) ; ( cmd_tx , metric_rx , handle ) }
Spawns an async cycle read thread that reports metrics.
Spawns an async cycle read thread that reports metrics .
mut self
metric
Metric<U>
cycle_period
CyclePeriod
timeout
Option<Duration>