[−][src]Module runtime::time
Types and Functions for time-related operations.
This module provides primitives for setting asynchronous timeouts, intervals, and delays.
Organization
Delay
andInterval
provide functionality for setting delays and intervals.FutureExt
extends Futures with the ability to time-out.- Other types are return or parameter types for various methods in this module
Examples
Delay execution for three seconds
use runtime::time::Delay; use std::time::{Duration, Instant}; let start = Instant::now(); let now = Delay::new(Duration::from_secs(3)).await; let elapsed = now - start; println!("elapsed: {}s", elapsed.as_secs());
Emit an event every two seconds
use runtime::time::Interval; use std::time::{Duration, Instant}; let start = Instant::now(); let mut interval = Interval::new(Duration::from_secs(2)); while let Some(now) = interval.next().await { let elapsed = now - start; println!("elapsed: {}s", elapsed.as_secs()); }
Structs
Delay | A future representing the notification that an elapsed duration has occurred. |
Interval | A stream representing notifications at a fixed interval. |
Timeout | A future returned by methods in the |
TimeoutAsyncRead | A stream returned by methods in the |
TimeoutStream | A stream returned by methods in the |
Traits
AsyncReadExt | Extend |
FutureExt | Extend |
StreamExt | Extend |