Struct AsyncTimerInterval

Source
pub struct AsyncTimerInterval<T = PosixTimer> {
    pub interval: Duration,
    /* private fields */
}
Expand description

Periodic Timer

On each completion, underlying timer is restarted and therefore Future can be polled once more.

§Usage

async fn job() {
}

async fn do_a_while() {
    let mut times: u8 = 0;
    let mut interval = async_timer::Interval::platform_new(core::time::Duration::from_secs(1));

    while times < 5 {
        job().await;
        interval.wait().await;
        times += 1;
    }
}

Fields§

§interval: Duration

Timer interval, change to this value will be reflected on next restart of timer.

Implementations§

Source§

impl Interval

Source

pub fn platform_new(interval: Duration) -> Interval

Creates new instance using platform timer

Source§

impl<T> Interval<T>
where T: Timer,

Source

pub fn new(interval: Duration) -> Interval<T>

Creates new instance with specified timer type.

Source

pub fn cancel(&mut self)

Stops interval

Source

pub fn restart(&mut self)

Restarts interval

Source

pub fn wait<'a>(&'a mut self) -> impl Future<Output = ()> + 'a

Returns future for next expiration.

Trait Implementations§

Source§

impl<T> Future for &mut Interval<T>
where T: Timer,

Source§

type Output = ()

The type of value produced on completion.
Source§

fn poll( self: Pin<&mut &mut Interval<T>>, ctx: &mut Context<'_>, ) -> Poll<<&mut Interval<T> as Future>::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl Intervalable for Interval

Source§

fn interval(dur: Duration) -> Self

Source§

fn wait<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>

Source§

fn wait_for_std<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Option<Instant>> + Send + 'a>>

Auto Trait Implementations§

§

impl<T> Freeze for Interval<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Interval<T>
where T: RefUnwindSafe,

§

impl<T> Send for Interval<T>
where T: Send,

§

impl<T> Sync for Interval<T>
where T: Sync,

§

impl<T> Unpin for Interval<T>
where T: Unpin,

§

impl<T> UnwindSafe for Interval<T>
where T: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more