liveBook · Manning

Scheduler

As explained in Code Like a Pro in Rust

A scheduler is a runtime component that determines when asynchronous tasks execute and switches between them.

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

How Code Like a Pro in Rust covers it

How deep it goes
Explains task switching, blocking, and yield points but defers detailed runtime internals.
Examples
Uses synchronous and Tokio timer programs to contrast blocking sleep with an awaited asynchronous timer.
What you can do after
Understand how yielding and blocking choices affect asynchronous task switching.
How it connects
Connects schedulers with asynchronous programming, runtimes, futures, .await, yield points, blocking I/O, and CPU-bound tasks.

Also explained in

Compare how 12 books explain scheduler →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Code Like a Pro in Rust. The section links point to the parts of the book it draws on.