tursodatabase avatar

Async Io Model

If you're working in Turso's core codebase, this is the pattern guide you'll need whenever touching I/O. It covers their cooperative async model built on explicit state machines and IOResult enums instead of Rust's async/await. The real value is in the re-entrancy pitfall section, which shows exactly how mutating state before a yield point causes subtle bugs when functions get called again after I/O completes. You get concrete examples of the state machine pattern, CompletionGroup for waiting on multiple operations, and the helper macros like return_if_io! that make it less painful to write. This is reference material for a specific codebase architecture, not a general async patterns guide.

skills.sh installs
1.3K
GitHub stars
25.2K
last updated
Aug 21, 2026

Install

$ npx -y skills add tursodatabase/turso --skill async-io-model --agent claude-code

Installs into .claude/skills of the current project.

Files

Async I/O Model Guide

Turso uses cooperative yielding with explicit state machines instead of Rust async/await.

Core Types

pub enum IOCompletions {
    Single(Completion),
}

#[must_use]
pub enum IOResult<T> {
    Done(T),      // Operation complete, here's the result
    IO(IOCompletions),  // Need I/O, call me again after completions finish
}

Functions returning IOResult must be called repeatedly until Done.

Completion and CompletionGroup

A Completion tracks a single I/O operation:

pub struct Completion { /* ... */ }

impl Completion {
    pub fn finished(&self) -> bool;
    pub fn succeeded(&self) -> bool;
    pub fn get_error(&self) -> Option<CompletionError>;
}

To wait for multiple I/O operations, use CompletionGroup:

let mut group = CompletionGroup::new(|_| {});

// Add individual completions
group.add(&completion1);
group.add(&completion2);

// Build into single completion that finishes when all complete
let combined = group.build();
io_yield_one!(combined);

Sponsors

Details

Repository
github.com/tursodatabase/turso
Category
Databases
First seen
May 16, 2026

More from tursodatabase/turso

All 14

Recommended

More Databases
1tursodatabase avatarpr-workflowtursodatabase/tursoGeneral guidelines for Commits, formatting, CI, dependencies, security1.2Kskills.sh installs
2duckdb avatarread-memoriesduckdb/duckdb-skillsSearch past Claude Code session logs to recall prior decisions, patterns, or unresolved work. Use when user says "do you remember", "what did we do", references872skills.sh installs
3supabase avatarskill-creatorsupabase/agent-skillsGuide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabil691skills.sh installs
4cockroachdb avatarcommit-helpercockroachdb/cockroachHelp create git commits and PRs with properly formatted messages and release notes following CockroachDB conventions. Use when committing changes or creating pu642skills.sh installs
5get-convex avatarfunction-creatorget-convex/agent-skillsCreate Convex queries, mutations, and actions with proper validation, authentication, and error handling. Use when implementing new API endpoints.560skills.sh installs
6get-convex avatarcomponents-guideget-convex/agent-skillsGuide to using Convex components for feature encapsulation. Learn about sibling components, creating your own, and when to use components vs monolithic code.555skills.sh installs