pub struct Periodic { /* private fields */ }
Expand description
Periodic async timer that fires at an interval.
Implements Stream
for continuous events and Future
for just the next event. The Stream
implementation never yields None
, so the stream never ends.
§Example
use std::time::Duration;
use local_runtime::time::Periodic;
use futures_lite::StreamExt;
let mut periodic = Periodic::periodic(Duration::from_secs(1));
loop {
// Print to screen once every second
periodic.next().await;
println!("One second has passed");
}
Implementations§
Source§impl Periodic
impl Periodic
Sourcepub fn periodic_at(start: Instant, period: Duration) -> Self
pub fn periodic_at(start: Instant, period: Duration) -> Self
Timer that fires periodically, starting from a set point in time
Sourcepub fn set_period(&mut self, period: Duration)
pub fn set_period(&mut self, period: Duration)
Change the period of the timer, effective after the next time it fires
Trait Implementations§
Source§impl Stream for Periodic
impl Stream for Periodic
Auto Trait Implementations§
impl Freeze for Periodic
impl RefUnwindSafe for Periodic
impl !Send for Periodic
impl Sync for Periodic
impl Unpin for Periodic
impl UnwindSafe for Periodic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more