Struct Interval

Source
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, ) -> Report

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) -> Report

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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 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.