Rust async and the tokio Scheduler
Calling an async fn runs none of its body; it only produces a Future value. A Future is a state machine that advances to the next await each time it is polled, and when it cannot advance it leaves a Waker behind and returns Pending. After the first poll its state depends on its own address, so Pin keeps it from being moved. On a tokio runtime with two workers, four std::thread::sleep(100ms) jobs occupied both workers and delayed a task that wakes every 10ms by about 200ms; moving the same jobs to spawn_blocking brought the delay back to the few milliseconds seen without blocking. The tenth and final post in a Rust study series.