pub fn sleep(duration: Duration, time_fn: fn() -> Duration) -> DurationSleepExpand description
Creates a future that will “sleep” for the specified Duration.
§Arguments
duration: Thecore::time::Durationto sleep for.time_fn: A function pointerfn() -> Durationthat returns the current monotonic time in nanoseconds. The user must provide this.
This function is no_std compatible (it only uses core types),
assuming the provided time_fn is also no_std compatible.
Examples found in repository?
examples/time.rs (line 16)
12fn main() {
13 let spawner: ato::Spawner<SPAWNER_SIZE> = ato::Spawner::default();
14 ato::spawn_task!(spawner, res, {
15 let start = Instant::now();
16 ato::sleep(Duration::from_millis(200), get_platform_time).await;
17 let elapsed = Instant::now().duration_since(start);
18 println!(
19 "Task 0 completed after {:?} milliseconds",
20 elapsed.as_millis()
21 );
22 });
23 res.unwrap();
24
25 spawner.run_until_all_done().unwrap();
26}