rust-async-internals
Installation
SKILL.md
Rust Async Internals
Decision table
| 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 set of spawned tasks and collect their results | JoinSet + join_next |
a bare Vec<JoinHandle> |
| Track a long-lived, unbounded task set (an accept loop) for shutdown | tokio_util::task::TaskTracker + close() + wait() |
a JoinSet that nobody drains; it keeps every result |
| Abort a task when its owner drops the handle | tokio_util::task::AbortOnDropHandle |
a bare JoinHandle; its drop detaches the task |
| 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 select! |
| Do bounded blocking or CPU work | spawn_blocking |
block_in_place |
| Run an indefinite blocking loop | std::thread::spawn |
spawn_blocking |
| Deliver every message without loss | mpsc |
broadcast |
Keep a critical .await sequence atomic |
tokio::spawn + join the handle |
select! around it |