pub struct Interval { /* private fields */ }
Expand description
Interval returned by interval
and interval_at
.
Implementations§
Source§impl Interval
impl Interval
Sourcepub fn tick(&mut self) -> Instant
pub fn tick(&mut self) -> Instant
Use SpinSleeper::sleep
to sleep until the next scheduled tick.
If the tick is in the past will return without sleeping
computing the next tick based on the configured MissedTickBehavior
.
Returns the tick time.
Sourcepub fn tick_no_spin(&mut self) -> Instant
pub fn tick_no_spin(&mut self) -> Instant
Use spin_sleep::native_sleep
to sleep until the next scheduled tick.
Does not spin.
If the tick is in the past will return without sleeping
computing the next tick based on the configured MissedTickBehavior
.
Returns the tick time.
Sourcepub fn missed_tick_behavior(&self) -> MissedTickBehavior
pub fn missed_tick_behavior(&self) -> MissedTickBehavior
Returns the MissedTickBehavior
strategy currently being used.
§Example
use spin_sleep_util::{interval, MissedTickBehavior};
let i = interval(Duration::from_millis(20));
assert_eq!(i.missed_tick_behavior(), MissedTickBehavior::Skip);
Sourcepub fn period(&self) -> Duration
pub fn period(&self) -> Duration
Returns the period of the interval.
§Example
use spin_sleep_util::interval;
let i = interval(Duration::from_millis(20));
assert_eq!(i.period(), Duration::from_millis(20));
Sourcepub fn set_period(&mut self, period: Duration)
pub fn set_period(&mut self, period: Duration)
Sets a new period.
Does not affect the existing scheduled next tick.
§Example
use spin_sleep_util::interval;
let mut i = interval(Duration::from_millis(20));
i.set_period(Duration::from_secs(1));
assert_eq!(i.period(), Duration::from_secs(1));
Sourcepub fn set_missed_tick_behavior(&mut self, behavior: MissedTickBehavior)
pub fn set_missed_tick_behavior(&mut self, behavior: MissedTickBehavior)
Sets the MissedTickBehavior
strategy that should be used.
§Example
use spin_sleep_util::{interval, MissedTickBehavior};
let mut i = interval(Duration::from_millis(20));
i.set_missed_tick_behavior(MissedTickBehavior::Burst);
assert_eq!(i.missed_tick_behavior(), MissedTickBehavior::Burst);
Sourcepub fn with_missed_tick_behavior(self, behavior: MissedTickBehavior) -> Self
pub fn with_missed_tick_behavior(self, behavior: MissedTickBehavior) -> Self
Returns Self
with the specified MissedTickBehavior
strategy.
§Example
use spin_sleep_util::{interval, MissedTickBehavior};
let i =
interval(Duration::from_millis(20)).with_missed_tick_behavior(MissedTickBehavior::Burst);
assert_eq!(i.missed_tick_behavior(), MissedTickBehavior::Burst);
Sourcepub fn spin_sleeper(&self) -> SpinSleeper
pub fn spin_sleeper(&self) -> SpinSleeper
Returns the configured SpinSleeper
.
§Example
use spin_sleep::SpinSleeper;
use spin_sleep_util::interval;
let i = interval(Duration::from_millis(20));
assert_eq!(i.spin_sleeper(), SpinSleeper::default());
Sourcepub fn set_spin_sleeper(&mut self, sleeper: SpinSleeper)
pub fn set_spin_sleeper(&mut self, sleeper: SpinSleeper)
Sets the SpinSleeper
used for accurate sleeping.
§Example
use spin_sleep_util::interval;
let mut i = interval(Duration::from_millis(20));
i.set_spin_sleeper(custom_sleeper);
assert_eq!(i.spin_sleeper(), custom_sleeper);
Sourcepub fn with_spin_sleeper(self, sleeper: SpinSleeper) -> Self
pub fn with_spin_sleeper(self, sleeper: SpinSleeper) -> Self
Returns Self
with the specified SpinSleeper
.
§Example
use spin_sleep_util::interval;
let i = interval(Duration::from_millis(20)).with_spin_sleeper(custom_sleeper);
assert_eq!(i.spin_sleeper(), custom_sleeper);