Skip to main content

Tick

Struct Tick 

Source
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

Source

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.

Source

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.

Source

pub fn interval(&self) -> Duration

Returns the interval duration.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.