Skip to content
Select theme

Async in practice

This is the chapter for when the async code compiles and still does not work. select!, spawned tasks that need a static lifetime, block_on inside a runtime, the Send error caused by a guard that lives one line too long.

Twelve articles, each one a problem that took somebody an afternoon.

Nothing published in this chapter yet — all 12 articles are still to come.

Coming up (12)
  • How to fix “there is no reactor running”the Tokio runtime is not started
  • What is the difference between Tokio and async-std?ecosystem, not features
  • How to wait on whichever finishes firstselect!, and the branches you must make cancel-safe
  • How to spawn a background tasktokio::spawn, and the ’static requirement
  • How to fix “future cannot be sent between threads safely”the guard you are holding across an await
  • How to hold a reference across an awaitwhy the guard has to go first
  • How to handle CPU-bound work in async codespawn_blocking, or a separate thread
  • How to configure the Tokio runtimeworker threads, the macros, and flavours
  • How to test async codethe tokio test attribute and its defaults
  • How to parallelise a loop with rayonchange iter to par_iter and check the total
  • How to run a task on a scheduleinterval, missed ticks, and the drift
  • How to shut down a service gracefullya shutdown signal, and the requests in flight