Rust Async Programming Quiz
Master asynchronous programming in Rust with futures, async/await, and concurrent execution patterns
Question 1
What is a Future in Rust?
Question 2
What does async fn do?
Question 3
What does await do?
Question 4
What does this basic async example do?
async fn hello() {
println!("Hello");
}
#[tokio::main]
async fn main() {
hello().await;
}Question 5
What is the difference between async blocks and async functions?
Question 6
What does this async block example show?
let future = async {
println!("In async block");
42
};
#[tokio::main]
async fn main() {
let result = future.await;
println!("Result: {}", result);
}Question 7
What is tokio?
Question 8
What is the difference between tokio::spawn and std::thread::spawn?
Question 9
What does this tokio::spawn example do?
#[tokio::main]
async fn main() {
let handle = tokio::spawn(async {
println!("In spawned task");
42
});
let result = handle.await.unwrap();
println!("Result: {}", result);
}Question 10
What is async I/O?
Question 11
What does tokio::fs provide?
Question 12
What is a Stream in async Rust?
Question 13
What does this Stream example show?
use tokio_stream::{self as stream, StreamExt};
#[tokio::main]
async fn main() {
let mut stream = stream::iter(vec![1, 2, 3]);
while let Some(value) = stream.next().await {
println!("Got: {}", value);
}
}Question 14
What is select!?
Question 15
What does this select! example do?
use tokio::select;
#[tokio::main]
async fn main() {
let task1 = tokio::spawn(async { tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; 1 });
let task2 = tokio::spawn(async { tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; 2 });
select! {
result = task1 => println!("Task 1 completed: {:?}", result),
result = task2 => println!("Task 2 completed: {:?}", result),
}
}Question 16
What is join!?
Question 17
What does this join! example show?
use tokio::join;
#[tokio::main]
async fn main() {
async fn task(n: u32) -> u32 {
tokio::time::sleep(tokio::time::Duration::from_secs(n)).await;
n
}
let (a, b, c) = join!(task(1), task(2), task(3));
println!("Results: {}, {}, {}", a, b, c);
}Question 18
What is async trait methods?
Question 19
What is the async_trait crate used for?
Question 20
What is Pin in async Rust?
Question 21
What is cooperative vs preemptive multitasking?
Question 22
What is async recursion?
Question 23
What is the solution to async recursion stack overflow?
Question 24
What is async closure?
Question 25
What does this async closure example do?
#[tokio::main]
async fn main() {
let async_closure = async |x: i32| {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
x * 2
};
let result = async_closure(5).await;
println!("Result: {}", result);
}Question 26
What is the difference between tokio::time::sleep and std::thread::sleep?
Question 27
What is timeout in tokio?
Question 28
What does this timeout example show?
use tokio::time::{timeout, Duration};
#[tokio::main]
async fn main() {
let result = timeout(Duration::from_secs(1), async {
tokio::time::sleep(Duration::from_secs(2)).await;
42
}).await;
match result {
Ok(value) => println!("Got: {}", value),
Err(_) => println!("Timeout!"),
}
}Question 29
What is async channel?
Question 30
What is the difference between bounded and unbounded channels?
Question 31
What is async mutex?
Question 32
What is the key difference between std::sync::Mutex and tokio::sync::Mutex?
Question 33
What is blocking code in async context?
Question 34
What does spawn_blocking do?
Question 35
What is async main?
Question 36
What is the async ecosystem in Rust?
Question 37
What is the difference between tokio and async-std?
Question 38
What is async testing?
Question 39
What is the performance advantage of async?
Question 40
In a web server handling thousands of concurrent HTTP requests, each making database queries and external API calls, which async patterns would you use and why?
