pub struct Timer { /* private fields */ }Expand description
A facility for scheduling timeouts
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn sleep(&self, duration: Duration) -> Sleep
pub fn sleep(&self, duration: Duration) -> Sleep
Returns a future that completes once the given instant has been reached
Sourcepub fn timeout<F>(&self, future: F, duration: Duration) -> Timeout<F>where
F: Future,
pub fn timeout<F>(&self, future: F, duration: Duration) -> Timeout<F>where
F: Future,
Allow the given future to execute for at most duration time.
If the given future completes within the given time, then the Timeout
future will complete with that result. If duration expires, the
Timeout future completes with a TimeoutError.
Sourcepub fn timeout_stream<T>(
&self,
stream: T,
duration: Duration,
) -> TimeoutStream<T>where
T: Stream,
pub fn timeout_stream<T>(
&self,
stream: T,
duration: Duration,
) -> TimeoutStream<T>where
T: Stream,
Allow the given stream to execute for at most duration time per
yielded value.
If the given stream yields a value within the allocated duration, then
value is returned and the timeout is reset for the next value. If the
duration expires, then the stream will error with a TimeoutError.
Sourcepub fn interval(&self, dur: Duration) -> Interval
pub fn interval(&self, dur: Duration) -> Interval
Creates a new interval which will fire at dur time into the future,
and will repeat every dur interval after
Sourcepub fn interval_at(&self, at: Instant, dur: Duration) -> Interval
pub fn interval_at(&self, at: Instant, dur: Duration) -> Interval
Creates a new interval which will fire at the time specified by at,
and then will repeat every dur interval after