rust-async-patterns

Implement concurrent Rust applications using Tokio tasks, channels, streams, and async error handling.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill rust-async-patterns-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-async-patterns
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/rust-async-patterns
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill rust-async-patterns-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct async Rust code is challenging: developers struggle with task coordination, channel selection, error propagation across await points, graceful shutdown, and deadlocks from holding locks across awaits. This Skill provides production-tested patterns for the Tokio ecosystem so you avoid common pitfalls. ## Core Features & Use Cases - Concurrency Patterns: Spawn and manage tasks with JoinSet, limit concurrency with buffer_unordered, and race futures with tokio::select!. - Communication & State: Choose between mpsc, broadcast, oneshot, and watch channels, plus RwLock and Semaphore-based resource pooling. - Error Handling & Shutdown: Structure errors with thiserror/anyhow, add timeouts, and implement graceful shutdown via CancellationToken or broadcast signals. - Use Case: When building a network service that must handle thousands of concurrent connections, apply the JoinSet pattern for request fan-out, wrap calls in timeout helpers, and shut down cleanly on Ctrl-C. ## Quick Start Ask the assistant to show how to run multiple async HTTP requests concurrently in Rust with Tokio, with a concurrency limit and proper error handling.

Frequently Asked Questions about rust-async-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run multiple async tasks concurrently in Rust with Tokio?

Use tokio::task::JoinSet to spawn and join multiple tasks, collecting results as each completes. For a concurrency limit, use futures::stream with buffer_unordered(n) to cap simultaneous executions.

Which Tokio channel should I use: mpsc, broadcast, oneshot, or watch?

Use mpsc for multi-producer single-consumer queues, broadcast for multi-consumer event distribution, oneshot for a single request-response value, and watch when consumers only need the latest state. Each has different delivery and buffering semantics.

How do I implement graceful shutdown in a Tokio application?

Use tokio_util::sync::CancellationToken and check token.cancelled() inside tokio::select! loops, then call token.cancel() after receiving signal::ctrl_c(). Alternatively, broadcast a shutdown signal to all worker tasks.

Why does my async Rust code deadlock when using Mutex?

Deadlocks occur when a lock guard is held across an .await point, blocking other tasks while the future is pending. Drop the guard before awaiting, or restructure to use channels instead of shared state.

Should I use anyhow or thiserror for async error handling in Rust?

Use anyhow with .context() for application-level code where you propagate rich error chains, and thiserror to define typed error enums for library code that callers match on. The patterns combine both with #[from] conversions.