pub struct Interval { /* private fields */ }
Expand description

Interval controller.

Implementations§

source§

impl Interval

source

pub async fn tick_with_min_interval( &mut self, minimum_interval: Duration ) -> Result<Report, Error>

Wait until next interval.

This function will return [SleepResult] which contains the duration that overly passed the specified interval. As it internally aligns to the specified interval, it should not be drifted over time, in terms of Instant clock domain.

  • minimum_interval: Minimum interval to wait. This prevents burst after long inactivity on Interval object.
source

pub async fn tick(&mut self) -> Result<Report, Error>

A shortcut for [tick_with_min_interval] with minimum_interval set to half.

source

pub fn set_interval(&mut self, interval: Duration)

Reset interval to the specified duration.

source

pub fn interval(&self) -> Duration

source

pub fn wakeup_time(&self) -> Instant

source

pub fn align_with_clock( &mut self, now_since_epoch: impl FnOnce() -> Duration, interval: Option<Duration>, initial_interval_tolerance: Option<Duration>, align_offset_ns: i64 )

This method aligns the subsequent tick to a given interval. Following the alignment, the timestamp will conform to the specified interval.

Parameters:

  • now_since_epoch: A function yielding the current time since the epoch. It’s internally converted to an Instant, hence, should return the most recent timestamp.
  • align_offset_ns: This parameter can adjust the alignment timing. For example, an offset of 100us applied to a next tick scheduled at 9000us will push the tick to 9100us.
  • initial_interval_tolerance: This defines the permissible noise level for the initial interval. If set to zero, the actual sleep duration will exceed the interval, potentially causing a tick to be skipped as the actual sleep duration might be twice the interval. It’s advisable to set it to 10% of the interval to prevent the align_clock command from disrupting the initial interval.

Note: For example, if now_since_epoch() gives 8500us and the interval is 1000us, the subsequent tick will be adjusted to 9000us, aligning with the interval.

source

pub fn align_now( &mut self, interval: Option<Duration>, initial_interval_tolerance: Option<Duration>, align_offset_ns: i64 )

Shortcut for [Self::align_clock] from now.

source

pub fn align_with_system_clock( &mut self, interval: Option<Duration>, initial_interval_tolerance: Option<Duration>, align_offset_ns: i64 )

Shortcut for [Self::align_clock] with std::time::SystemTime as the time source.

Trait Implementations§

source§

impl Clone for Interval

source§

fn clone(&self) -> Interval

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Interval

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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 Twhere U: TryFrom<T>,

§

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.