Complete these tasks to reinforce what you learned in this module.
Write an async fn add_async(a: i32, b: i32) -> i32 that returns a + b. In async fn main (with #[tokio::main]), call add_async(10, 32).await and print the result.
async fn returns a future; call it with .await inside an async context. Main must be async fn main() with #[tokio::main] so the runtime runs it.// Task 1: async add_async. See tasks/TASKS.md.
fn main() {
todo!("Use #[tokio::main] async fn main, add_async(10, 32).await, print sum");
}
In async fn main, use tokio::spawn to run a task that prints "spawned". Await a short delay (e.g. tokio::time::sleep(Duration::from_millis(50)).await) so the spawned task can run, then print "main".
tokio::spawn takes an async block. Give the spawned task a moment to run (e.g. sleep) before printing from main. You don’t have to await the join handle for this task.// Task 2: tokio::spawn. See tasks/TASKS.md.
fn main() {
todo!("tokio::spawn task that prints spawned, sleep, print main");
}