Rust Async
Rule
Make task ownership, cancellation, timeouts, backpressure, and shutdown explicit. Use async
only when it solves real I/O concurrency needs.
Hard Stops
Stop when:
- Runtime ownership, cancellation, task supervision, or shutdown behavior is unclear.
- Blocking work is inside async tasks without
spawn_blocking or isolation.
Send/Sync constraints are bypassed without understanding.
- Tests rely on sleeps rather than deterministic synchronization or paused time.
- A library tries to create or own a global Tokio runtime without approval.
Defaults
- Use Tokio for greenfield async apps when approved.
- Libraries should expose async APIs without owning the runtime.
- Use
tokio::time::timeout, cancellation tokens or context-like shutdown channels, and
explicit JoinHandle ownership.
- Prefer bounded
tokio::sync::mpsc channels for backpressure.
- Use
select! carefully and handle cancellation safety.
- Use
tracing spans for long-lived tasks and I/O boundaries when observability is in
scope.
- Use
tokio::test(start_paused = true) where time control is needed.
Workflow
- Define concurrency goal, runtime ownership, shared state, and task lifecycle.
- Design cancellation, timeouts, backpressure, error propagation, and cleanup.
- Avoid holding mutex guards across
.await unless using async-aware locks and justified.
- Add deterministic async tests with paused time, controlled channels, or explicit
synchronization.
- Run async tests, full tests, Clippy, and
just check.
Antipatterns
- Fire-and-forget tasks with dropped
JoinHandles.
- Unbounded channels or task spawning per request/item without limits.
- Blocking filesystem/CPU work on the async runtime.
Arc<Mutex<_>> shared state with lock guards crossing awaits.
- Treating cancellation as success without cleanup.
Completion
Report runtime model, task lifecycle, cancellation/backpressure choices, tests, and risks.
Source: nyquistwilder/personal-pi — distributed by TomeVault.
1---2name: rust-async-43description: Async Rust workflow for Tokio, futures, cancellation, timeouts, task lifecycle, channels, streams, Send/Sync boundaries, graceful shutdown, backpressure, and deterministic async tests. Use when this capability is needed.4---56# Rust Async78## Rule910Make task ownership, cancellation, timeouts, backpressure, and shutdown explicit. Use async11only when it solves real I/O concurrency needs.1213## Hard Stops1415Stop when:1617- Runtime ownership, cancellation, task supervision, or shutdown behavior is unclear.18- Blocking work is inside async tasks without `spawn_blocking` or isolation.19- `Send`/`Sync` constraints are bypassed without understanding.20- Tests rely on sleeps rather than deterministic synchronization or paused time.21- A library tries to create or own a global Tokio runtime without approval.2223## Defaults2425- Use Tokio for greenfield async apps when approved.26- Libraries should expose async APIs without owning the runtime.27- Use `tokio::time::timeout`, cancellation tokens or context-like shutdown channels, and28 explicit `JoinHandle` ownership.29- Prefer bounded `tokio::sync::mpsc` channels for backpressure.30- Use `select!` carefully and handle cancellation safety.31- Use `tracing` spans for long-lived tasks and I/O boundaries when observability is in32 scope.33- Use `tokio::test(start_paused = true)` where time control is needed.3435## Workflow36371. Define concurrency goal, runtime ownership, shared state, and task lifecycle.382. Design cancellation, timeouts, backpressure, error propagation, and cleanup.393. Avoid holding mutex guards across `.await` unless using async-aware locks and justified.404. Add deterministic async tests with paused time, controlled channels, or explicit41 synchronization.425. Run async tests, full tests, Clippy, and `just check`.4344## Antipatterns4546- Fire-and-forget tasks with dropped `JoinHandle`s.47- Unbounded channels or task spawning per request/item without limits.48- Blocking filesystem/CPU work on the async runtime.49- `Arc<Mutex<_>>` shared state with lock guards crossing awaits.50- Treating cancellation as success without cleanup.5152## Completion5354Report runtime model, task lifecycle, cancellation/backpressure choices, tests, and risks.5556---57> Source: [nyquistwilder/personal-pi](https://github.com/nyquistwilder/personal-pi) — distributed by [TomeVault](https://tomevault.io).58<!-- tomevault:4.0:skill_md:2026-06-16 -->