rust-async-internalslisted
Install: claude install-skill po4yka/rust-skills
# Rust Async Internals
## When to use this skill
Use this skill when you do one of these things:
- You author or review an `async fn` that can be polled inside `tokio::select!`,
`tokio::time::timeout`, `JoinSet`, or `FuturesUnordered`.
- You bridge a foreign thread (JNI, a C callback, a platform service thread)
into a tokio runtime with `block_on`.
- You configure a runtime for a constrained target, or you decide between
`current_thread` and `multi_thread`.
- You design shutdown with `CancellationToken`.
- You choose between `spawn_blocking`, `block_in_place`, and
`std::thread::spawn`.
- You poll a future by hand from a synchronous loop.
- You diagnose a stall, a shutdown hang, a latency spike, or a silent message
loss.
## Decision table
Read this table first. It answers most async design questions in one line.
| You must | Use | Do not use |
|---|---|---|
| Run N futures and keep only the first result | `tokio::select!` | `join!` |
| Run N futures to completion | `tokio::join!` or `try_join!` | `select!` |
| Own a dynamic set of spawned tasks | `JoinSet` | a bare `Vec<JoinHandle>` |
| Bound the concurrency of a work stream | `stream::iter(..).buffer_unordered(K)` | `spawn` in an unbounded loop |
| Shut down a task tree | `CancellationToken` + `child_token()` | `Notify` |
| Cancel on any early return or panic | `token.drop_guard()` | manual cleanup at each `?` |
| Race work against shutdown and keep the value | `token.run_until_cancelled(fut)` | a hand-written