Complete these tasks to reinforce what you learned in this module.
Spawn a task with tokio::spawn that sleeps for 100 ms then prints "background". In main, print "main", then await the spawn handle. Use #[tokio::main].
tokio::spawn with an async block that sleeps then prints. In main, print your line, then await the join handle so the program doesn’t exit before the task runs.// Task 1: Spawn and await. See tasks/TASKS.md.
fn main() {
todo!("tokio::spawn sleep+print, main print, await handle");
}
In a spawned task, create an interval of 200 ms and loop 3 times: tick, then print "tick". After the loop, print "done". In main, await the spawn handle. Use tokio::time::interval.
tokio::time::interval and a duration. In a loop (e.g. 3 times), await the next tick, then print. The theory shows the interval API.// Task 2: Interval loop. See tasks/TASKS.md.
fn main() {
todo!("Spawn task with interval, 3 ticks, await");
}