---
name: "tokio-asynchronous-runtime-tasks"
description: "Execute asynchronous I/O, spawn green threads, and communicate via channels with Tokio."
metadata:
  author: "Tokio"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "tokio spawn background task"
  - "tokio mpsc channel"
  - "tokio select macro timeout"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Tokio Asynchronous Runtime, Tasks & Channels in Rust

Operates Tokio: configuring #[tokio::main] multi-threaded runtime, spawning background tasks (tokio::spawn), channels (mpsc, broadcast, oneshot), select! macro for cancellation/timeouts, and graceful shutdown.

## When to Invoke
Invoke this skill whenever you need to:
- tokio spawn background task
- tokio mpsc channel
- tokio select macro timeout

## Execution SOP & Rules
1. Initialize runtime: #[tokio::main(flavor = 'multi_thread', worker_threads = 4)] async fn main() { ... }.
2. Spawn task: let handle = tokio::spawn(async move { do_work().await });
3. Create channel: let (tx, mut rx) = mpsc::channel(32); tx.send(item).await?; while let Some(i) = rx.recv().await { ... }.
4. Handle timeouts: tokio::select! { res = heavy_task() => res, _ = tokio::time::sleep(dur) => Err('timeout') }.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
