rs-async-patterns
/rs-async-patterns
Use for async architecture beyond the basics — actors and mailboxes, supervision, graceful shutdown, streams and backpressure, cancellation, Pin/Unpin and hand-written futures, spawning with 'static, bounded concurrency. Triggers: actor, actor model, mailbox, supervision tree, supervisor, ractor, kameo, actix, message passing, graceful shutdown, CancellationToken, TaskTracker, drain, SIGTERM, Stream, StreamExt, backpressure, bounded channel, buffer_unordered, select!, cancel safety, timeout, Pin, Unpin, pin!, Box::pin, pin-project, self-referential future, impl Future, poll, Waker, tokio::spaw
- Author
- bassem-elsodany ↗
- Repository
- rs-skills ↗
- Licence
- MIT
- Last repository change
- 11.11.2026
Assessment and security
- Files in this package
- 9
- Scripts
- 0
- HTML comments
- 2
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 11.11.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
- SKILL.md zawiera komentarze HTML (2). Nie widać ich w podglądzie Markdown, a model je czyta.
What it does and when to use it
Use for async architecture beyond the basics — actors and mailboxes, supervision, graceful shutdown, streams and backpressure, cancellation, Pin/Unpin and hand-written futures, spawning with 'static, bounded concurrency. Triggers: actor, actor model, mailbox, supervision tree, supervisor, ractor, kameo, actix, message passing, graceful shutdown, CancellationToken, TaskTracker, drain, SIGTERM, Stream, StreamExt, backpressure, bounded channel, buffer_unordered, select!, cancel safety, timeout, Pin, Unpin, pin!, Box::pin, pin-project, self-referential future, impl Future, poll, Waker, tokio::spaw
Original author description
Use for async architecture beyond the basics — actors and mailboxes, supervision, graceful shutdown, streams and backpressure, cancellation, Pin/Unpin and hand-written futures, spawning with 'static, bounded concurrency. Triggers: actor, actor model, mailbox, supervision tree, supervisor, ractor, kameo, actix, message passing, graceful shutdown, CancellationToken, TaskTracker, drain, SIGTERM, Stream, StreamExt, backpressure, bounded channel, buffer_unordered, select!, cancel safety, timeout, Pin, Unpin, pin!, Box::pin, pin-project, self-referential future, impl Future, poll, Waker, tokio::spaw
How it works
- Core Question
- Thinking Prompt
- Decision table
- The five rules
- Trace
- Rules (4)
- Related Skills
SKILL.md preview
--- name: rs-async-patterns description: "Use for async architecture beyond the basics — actors and mailboxes, supervision, graceful shutdown, streams and backpressure, cancellation, Pin/Unpin and hand-written futures, spawning with 'static, bounded concurrency. Triggers: actor, actor model, mailbox, supervision tree, supervisor, ractor, kameo, actix, message passing, graceful shutdown, CancellationToken, TaskTracker, drain, SIGTERM, Stream, StreamExt, backpressure, bounded channel, buffer_unordered, select!, cancel safety, timeout, Pin, Unpin, pin!, Box::pin, pin-project, self-referential future, impl Future, poll, Waker, tokio::spawn 'static, JoinSet, semaphore, bounded concurrency, structured concurrency, async trait object" user-invocable: false --- # Async Patterns — architecture for long-running async programs > **Layer 1/2: Mechanics + Design** · what rs-concurrency's rules assume you already decided > > Depth: `guides/actors.md` · `guides/shutdown-and-supervision.md` · `guides/streams-and-backpressure.md` · `guides/pin-and-futures.md` · basic rules live in rs-concurrency (`async-*`) ## Core Question **Who owns this state, who may wait for whom, and what happens when the program is told to stop?** Async bugs are rarely syntax; they are ownership of state across tasks, unbounded queues, work that is cancelled half-way, and shutdowns that never finish. Decide these four before writing the first `spawn`. --- ## Thinking Prompt 1. **State:** shared with a lock, or *owned by one task* that others talk to? (Owned-by-one-task is the actor pattern — no `Mutex`, no lock-across-`.await`.) 2. **Queues:** is every channel/stream/buffer **bounded**? An unbounded queue is an out-of-memory bug waiting for a slow consumer. 3. **Cancellation:** if this future is dropped at any `.await`, is the state still consistent? (cancel safety — `select!` drops the losers) 4. **Shutdown:** how does each task learn to stop, how long may it take, who waits for it? 5. **Lifetimes:** does spawned work need borrowed data? (`tokio::spawn` needs `'static`: move/`Arc`, or use scoped/structured concurrency.) ## Decision table | Situation | Use | Detail | |---|---|---| | mutable state touched from many tasks | **actor**: one task owns it, handles messages from a bounded `mpsc`; replies via `oneshot` | `guides/actors.md` | | need restart-on-crash, many actors, remote actors | an actor framework (`ractor`, `kameo`, `actix`) — don't build supervision trees by hand | `guides/actors.md` | | process must exit cleanly on SIGTERM | one `CancellationToken` + `TaskTracker`, drain with a deadline | `guides/shutdown-and-supervision.md` | | a producer faster than its consumer | bounded channel / `Stream` with `buffer_unordered(n)` / semaphore; let `send().await` push back | `guides/streams-and-backpressure.md` | | first of several futures wins | `tokio::select!` — only with cancel-safe branches | rs-concurrency `async-select-racing`, `async-cancel-safety` | | N things in parallel, fail fast | `JoinSet` / `try_join!` | rs-concurrency `async-joinset-structured`, `async-try-join` | | limit parallelism | `Semaphore`, `buffer_unordered(n)`, never `spawn` in an unbounded loop | `guides/streams-and-backpressure.md` | | wrap/instrument a future, implement a combinator | `pin_project_lite`, `Pin<&mut Self>`; `Box::pin` for erasure; `std::pin::pin!` for the stack | `guides/pin-and-futures.md` | | blocking or CPU-bound call inside async | `spawn_blocking` / rayon, never `std::thread::sleep` or heavy loops in a task | rs-concurrency `async-spawn-blocking` | | `dyn` async trait | `#[async_trait]`/`trait_variant`, or enum dispatch | rs-ports-adapters `port-async-and-dyn` | ## The five rules 1. **Bound every queue.** `mpsc::channel(n)`, not `unbounded_channel()`; decide per queue what happens when full (wait, drop oldest, fail). 2. **One owner per piece of state.** Prefer a task that owns it over `Arc<Mutex<…>>`; if you must lock, never hold the guard across `.await`. 3. **Every long-running task takes a cancellation signal** and finishes its current unit of work before exiting; the program waits for them with a deadline. 4. **`select!` only with cancel-safe branches**, or loop with the future pinned outside the `select!` so it is not dropped (`pin!`). 5. **No fire-and-forget `tokio::spawn` without a handle** you either await, track (`TaskTracker`/`JoinSet`) or deliberately detach with a comment saying why. ## Trace | Direction | Go to | |---|---| | ↑ Up | rs-domain-cloud-native (shutdown on SIGTERM, health), rs-domain-iot/-web (what the loop serves), rs-domain-distributed (timeouts, retries across the network) | | ↓ Down | rs-concurrency (Send/Sync, channels, rules), rs-mutability (locks), rs-lifecycle (Drop, pools), rs-traits (async traits) | | → Delivery | rs-testing (`#[tokio::test(start_paused = true)]` for time, loom/shuttle for races), rs-observability (task and span context), rs-cleanup (no leaked processes) | <!-- rules-index:start --> ## Rules (4) Depth rules under `rules/` — open the one the question needs, not all of them. **async-** - [`async-actor-owns-state`](rules/async-actor-owns-state.md) — Let one task own mutable state and talk to it through a bounded mailbox - [`async-bound-every-queue`](rules/async-bound-every-queue.md) — Bound every channel, buffer and in-flight set; decide what "full" means - [`async-graceful-shutdown`](rules/async-graceful-shutdown.md) — Every long-running task takes a cancellation token; shutdown drains with a deadline - [`async-no-bare-spawn`](rules/async-no-bare-spawn.md) — Don't fire-and-forget `tokio::spawn`; track the handle or say why it is detached <!-- rules-index:end --> --- ## Related Skills | When | See | |---|---| | Send/Sync, channels, `async-*` rules | rs-concurrency | | Retry, circuit breaker | rs-domain-error | | Distributed timeouts and idempotency | rs-domain-distributed | | Ownership of data across tasks | rs-ownership, rs-resource |
Files in this package (9)
- SKILL.md 6 KB
- guides/actors.md 4 KB
- guides/pin-and-futures.md 3 KB
- guides/shutdown-and-supervision.md 3 KB
- guides/streams-and-backpressure.md 2 KB
- rules/async-actor-owns-state.md 1 KB
- rules/async-bound-every-queue.md 1 KB
- rules/async-graceful-shutdown.md 1 KB
- rules/async-no-bare-spawn.md 1 KB
Versions
The database has no other skills named rs-async-patterns.
Database snapshot: 13.11.2026 · package version a984cf5e67df (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 100rust-async-internals
Use when understanding the Rust Future poll model, Pin and Unpin, tokio scheduling, async stack traces, waker leaks, or select!/join! behavior. - 100rust-async-internals
Use when understanding the Rust Future poll model, Pin and Unpin, tokio scheduling, async stack traces, waker leaks, or select!/join! behavior. - 100rust-async-internals
Rust async internals skill for understanding and debugging async Rust. Use when understanding the Future trait and poll model, Pin and Unpin, tokio task scheduling, debugging async stack traces with tokio-console, tracking waker leaks, using select! and join!, or avoiding… - 90rust-async-tokio
Tokio async patterns for Cybercore Rust applications. Use for runtimes, spawn, spawn_blocking, cancellation, graceful shutdown, timeouts, and bounded concurrency. Library error and MSRV rules stay in rust-development. - 90cc-rust-async
Use when Rust futures, Tokio tasks, cancellation safety, bounded async concurrency, blocking boundaries or shutdown behavior need implementation or diagnosis. - 100rust-concurrency
Design, implement, diagnose, and test Rust concurrency and parallelism with threads, Send and Sync, locks, atomics, channels, Tokio, Rayon, Crossbeam, bounded backpressure, actor ownership, task supervision, graceful shutdown, runtime diagnostics, and Loom model tests. Use when…