A scheduler is the runtime component that decides which asynchronous task runs next. Tasks must yield, usually at .await points, so the runtime can switch between them. section 8.3
Use scheduler-aware control flow to keep asynchronous programs responsive:
- Avoid synchronous sleep and other operations that block task switching. section 8.3
- Treat slow I/O and sufficiently long CPU-bound work as blocking operations. section 8.3
- Introduce yield points by awaiting or joining futures. section 8.3
fn main() {
use std::time;
let duration = time::Duration::from_secs(1);
tokio::runtime::Builder::new_current_thread()
.enable_time() #1
.build()
.unwrap()
.block_on(async { #2
tokio::time::sleep(duration).await;
println!("Hello, world!");
});
}
Compare a Tokio runtime, timer future, and .await yield point in a minimal Rust program. section 8.3











