rust-async-patterns

Installation
SKILL.md

Rust async patterns (Tokio)

Use when building async Rust: HTTP servers (Axum), workers, sqlx, reqwest, streams, and concurrency.

Runtime and tasks

  • Use tokio::spawn for fire-and-forget work only when errors are logged or joined; prefer JoinSet / join! when you need all outcomes.
  • Don’t block the runtime: avoid std::thread::sleep, heavy sync mutex work, or CPU-bound loops on async worker threads—offload to spawn_blocking or rayon when measured.

Cancellation and shutdown

  • Prefer tokio::select! for racing work vs shutdown signals; propagate cancellation to child tasks when libraries support it.
  • JoinHandle::abort is a hammer; understand whether I/O or DB operations clean up correctly.

Locks in async

  • Avoid holding std::sync::Mutex across .await—use tokio::sync::Mutex for short critical sections in async contexts, or restructure to not hold locks over await points.
  • RwLock: choose tokio::sync::RwLock when guards cross await; parking_lot only when stays synchronous.
Installs
1
First Seen
Apr 12, 2026
rust-async-patterns — alexandretrotel/skills