pub fn sleep(&mut self) {
    match self.last_instant {
      None => self.last_instant = Some(Instant::now()),
      Some(last) => {
        self.cycles += 1;
        let now = Instant::now();
        let dur = now.duration_since(last);
        let subsec_nanos = dur.subsec_nanos();
        self.last_instant = Some(now);
        if dur.as_secs() > 0 || subsec_nanos > self._period_nanos {
          self.slips += 1;
          return;
        } else {
          thread::sleep(Duration::new(0, self._period_nanos - subsec_nanos));
        }
        if self.cycles == self._freq && self.slips > 0 {
          // If we have had slippage within the last second ( approx )
          // then we log it.
          if log_enabled!(Warn) {
            warn!("'{}' slipped {} times in last second", self.tag, self.slips);
          }
          self.slips = 0;
          self.cycles = 0;
        }
      }
    }
  }
/// When called repeatedly in a loop, tries to
/// sleep the proper amount needed to ensure the loop
/// runs at the given frequency
When called repeatedly in a loop, tries to
sleep the proper amount needed to ensure the loop
runs at the given frequency
When called repeatedly in a loop tries to sleep the proper amount needed to ensure the loop runs at the given frequency
pub fn sleep(&mut self) {
    match self.last_instant {
      None => self.last_instant = Some(Instant::now()),
      Some(last) => {
        self.cycles += 1;
        let now = Instant::now();
        let dur = now.duration_since(last);
        let subsec_nanos = dur.subsec_nanos();
        self.last_instant = Some(now);
        if dur.as_secs() > 0 || subsec_nanos > self._period_nanos {
          self.slips += 1;
          return;
        } else {
          thread::sleep(Duration::new(0, self._period_nanos - subsec_nanos));
        }
        if self.cycles == self._freq && self.slips > 0 {
          // If we have had slippage within the last second ( approx )
          // then we log it.
          if log_enabled!(Warn) {
            warn!("'{}' slipped {} times in last second", self.tag, self.slips);
          }
          self.slips = 0;
          self.cycles = 0;
        }
      }
    }
  }
pub fn sleep ( & mut self ) { match self . last_instant { None => self . last_instant = Some ( Instant :: now ( ) ) , Some ( last ) => { self . cycles += 1 ; let now = Instant :: now ( ) ; let dur = now . duration_since ( last ) ; let subsec_nanos = dur . subsec_nanos ( ) ; self . last_instant = Some ( now ) ; if dur . as_secs ( ) > 0 || subsec_nanos > self . _period_nanos { self . slips += 1 ; return ; } else { thread :: sleep ( Duration :: new ( 0 , self . _period_nanos - subsec_nanos ) ) ; } if self . cycles == self . _freq && self . slips > 0 { // If we have had slippage within the last second ( approx ) // then we log it. if log_enabled ! ( Warn ) { warn ! ( " " self tag self slips ) ; } self . slips = 0 ; self . cycles = 0 ; } } } }
When called repeatedly in a loop, tries to
sleep the proper amount needed to ensure the loop
runs at the given frequency
When called repeatedly in a loop tries to sleep the proper amount needed to ensure the loop runs at the given frequency
&mut self
&mut self