[][src]Struct ndless_async::timer::Interval

pub struct Interval { /* fields omitted */ }

A timer that keeps re-triggering.

Use TimerListener::every, TimerListener::every_hz, TimerListener::every_ms, or TimerListener::every_ticks to get an Interval.

This implements Stream, giving the Duration of time ago when this should have been triggered. If a task takes a lot of time, the Stream will only produce one event. This is likely what you want for handling events like keypad input, as only one event will trigger after blocking for a while, rather than many events being triggered right after the blocking event.

use ndless_async::StreamExt;
use ndless_async::task::{block_on, AsyncListeners};

let listeners = AsyncListeners::new();
block_on(&listeners, async {
    let mut interval = listeners.timer().every_ms(1000);
    while let Some(d) = interval.next().await {
        println!("Ping! This event was expected {:?} ago", d);
    }
});

Implementations

impl Interval[src]

pub fn interval(&self) -> Duration[src]

The interval that this Interval triggers

pub fn interval_ms(&self) -> u32[src]

The interval, in milliseconds, that this Interval triggers

pub fn interval_ticks(&self) -> u32[src]

The interval, in ticks, that this Interval triggers

pub fn reschedule_ms(&mut self, ms: u32)[src]

Reschedules this interval for the specified number of milliseconds. Problems will occur when sleeping for more than 2^31/32768 seconds, which is about 18 hours.

pub fn reschedule(&mut self, dur: Duration)[src]

Reschedules this interval for the specified Duration. Problems will occur when sleeping for more than 2^31/32768 seconds, which is about 18 hours.

This function has a resolution of 30 μs.

pub fn reschedule_ticks(&mut self, ticks: u32)[src]

Reschedules this interval for the specified number of ticks. Problems will occur when sleeping for more than 2^31 ticks, which is about 18 hours.

Trait Implementations

impl Stream for Interval[src]

type Item = Duration

The difference between now and when this event should have occurred.

Auto Trait Implementations

impl !Send for Interval

impl !Sync for Interval

impl Unpin for Interval

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.