Rust Async Patterns

SkillAI & models

A skill that gives an AI agent reference material and best practices for async Rust programming with the Tokio runtime. It covers futures, tasks, channels, streams, and error handling, and is meant for building async Rust applications, implementing concurrent systems, or debugging async code. The skill includes quick-start setup, core concepts, and do's and don'ts, with deeper patterns in a referenced details file.

Then ask your AI: use the Rust Async Patterns skill

Details

Instructions available. Your AI can read the instructions. Execution depends on the setup they require.

Have an AI agent that can load skills and a Rust project where you want async code.

What your AI can do with it

  • Explains the async execution model: futures, poll, wakers, and runtimes
  • Shows Tokio setup with tokio, futures, async-trait, anyhow, and tracing
  • Covers tasks, channels, streams, and JoinSet for concurrency
  • Lists do's and don'ts such as avoiding blocking calls in async code
  • Points to references/details.md for deeper patterns and worked examples

Getting started

  1. Have an AI agent that can load skills and a Rust project where you want async code.
  2. Add the skill so the agent can read its instructions and the references/details.md file.
  3. Add the listed dependencies to Cargo.toml: tokio with the full feature, futures, async-trait, anyhow, tracing, and tracing-subscriber.
  4. Ask the agent to apply the patterns when writing or debugging async Rust code.

What this skill tells your AI

The instructions your AI receives, as published by wshobson/agents in plugins/systems-programming/skills/rust-async-patterns/SKILL.md and read by Ahel’s review.

Production patterns for async Rust programming with Tokio runtime, including tasks, channels, streams, and error handling.

When to Use This Skill

  • Building async Rust applications
  • Implementing concurrent network services
  • Using Tokio for async I/O
  • Handling async errors properly
  • Debugging async code issues
  • Optimizing async performance

Core Concepts

1. Async Execution Model

Future (lazy) → poll() → Ready(value) | Pending
                ↑           ↓
              Waker ← Runtime schedules

2. Key Abstractions

ConceptPurpose
FutureLazy computation that may complete later
async fnFunction returning impl Future
awaitSuspend until future completes
TaskSpawned future running concurrently
RuntimeExecutor that polls futures

Quick Start

# Cargo.toml
[dependencies]
tokio = { version = "1", features = ["full"] }
futures = "0.3"
async-trait = "0.1"
anyhow = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"
use tokio::time::{sleep, Duration};
use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    // Initialize tracing
    tracing_subscriber::fmt::init();

    // Async operations
    let result = fetch_data("https://api.example.com").await?;
    println!("Got: {}", result);

    Ok(())
}

async fn fetch_data(url: &str) -> Result<String> {
    // Simulated async operation
    sleep(Duration::from_millis(100)).await;
    Ok(format!("Data from {}", url))
}

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

Do's

  • Use tokio::select! - For racing futures
  • Prefer channels - Over shared state when possible
  • Use JoinSet - For managing multiple tasks
  • Instrument with tracing - For debugging async code
  • Handle cancellation - Check CancellationToken

Don'ts

  • Don't block - Never use std::thread::sleep in async
  • Don't hold locks across awaits - Causes deadlocks
  • Don't spawn unboundedly - Use semaphores for limits
  • Don't ignore errors - Propagate with ? or log
  • Don't forget Send bounds - For spawned futures

Signals

GitHub stars
40k
Forks
4k
Last commit
Oct 2026

Questions

What does this skill cover?
It covers async Rust with the Tokio runtime: futures, tasks, channels, streams, error handling, quick-start setup, core concepts, and do's and don'ts, with deeper patterns in a referenced details file.
When should I use it?
Use it when building async Rust applications, implementing concurrent network services, using Tokio for async I/O, handling async errors, debugging async code, or optimizing async performance.
Does it support async traits?
Yes. The quick-start setup includes the async-trait crate, and async traits are part of the async patterns the skill covers.
Advanced
Item type
skill
Key
rust-async-patterns-wshobson
Source
github.com/wshobson/agents