pub struct Tick { /* private fields */ }Expand description
Drift-free periodic scheduler.
Tick tracks the next deadline and sleeps only for the remaining time,
so accumulated processing time doesn’t cause the interval to drift.
On overrun (work exceeds one interval), the deadline advances by the smallest number of whole intervals that lands in the future, preserving phase alignment with the original schedule.
§Example
use std::time::Duration;
use sysprims_core::time::Tick;
let mut tick = Tick::new(Duration::from_secs(5)).unwrap();
loop {
// do work …
tick.sleep_until_next();
}Implementations§
Source§impl Tick
impl Tick
Sourcepub fn new(interval: Duration) -> SysprimsResult<Self>
pub fn new(interval: Duration) -> SysprimsResult<Self>
Create a new Tick that fires at interval from now.
Returns InvalidArgument if interval is less than 1 ms.
Sourcepub fn sleep_until_next(&mut self)
pub fn sleep_until_next(&mut self)
Sleep until the next tick deadline, then advance the deadline.
If the deadline has already passed (work took longer than one interval), this returns immediately and advances by the smallest whole-interval multiple that lands in the future, preserving phase alignment.
Auto Trait Implementations§
impl Freeze for Tick
impl RefUnwindSafe for Tick
impl Send for Tick
impl Sync for Tick
impl Unpin for Tick
impl UnsafeUnpin for Tick
impl UnwindSafe for Tick
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more