tursodatabase avatar

Async Io Model

Explicit state-machine pattern for IOResult-based I/O in Turso's core, with re-entrancy and completion-group guidance.

skills.sh installs
1.3K
GitHub stars
25.3K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers the IOResult contract, where a function is called repeatedly until it returns Done instead of using async/await
  • Includes the return_if_io! and io_yield_one! macros, CompletionGroup for waiting on several completions, and a state-machine loop example
  • Enforces a re-entrancy rule: state mutations before a yield repeat on every call, so changes belong after the yield or in the next state
  • Designed for developers writing or changing core code that returns IOResult or keeps I/O state across yields

Install

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

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Async I/O model

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

Types

pub enum IOResult<T> {
    Done(T),            // finished, here is the result
    IO(IOCompletions),  // wait for the completion, then call again
}
pub struct IOCompletions(pub Completion);
pub type IOResultOr<T> = Result<IOResult<T>, Box<LimboError>>;

A function returning IOResult is called repeatedly until it returns Done.

To wait for several completions, add them to a CompletionGroup and yield the built completion. It finishes when all complete or one fails, can be nested, and can be cancelled with group.cancel():

let mut group = CompletionGroup::new(|_| {});
group.add(&completion1);
group.add(&completion2);
io_yield_one!(group.build());

Macros

  • return_if_io!(expr) unwraps Done(v) to v and returns the IO variant to the caller.
  • io_yield_one!(c) returns Ok(IOResult::IO(IOCompletions(c))).

State machines

Keep progress in a state enum, loop on it, and set the next state before each yield:

Details

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

More from tursodatabase/turso

All 7

Similar to Async Io Model

More Rust