Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

async-io-model

БесплатноБез исполняемых скриптовНе проверен

Use when writing or changing code that returns IOResult or keeps I/O state across yields - state machines, re-entrancy, CompletionGroup

tursodatabaseот tursodatabase★ 25 410 звёзд на GitHub

Об этом скилле

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:

loop {
    match &mut self.state {
        State::Start => {
            let (page, completion) = start_read();
            self.state = State::WaitingForRead { page };
            io_yield_one!(completion);
        }
        State::WaitingForRead { page } => {
            let data = page.get_contents().to_vec();
            self.state = State::Processing { data };
        }
        State::Processing { data } => return Ok(IOResult::Done(process(data))),
    }
}

If a field is used in only one or two states, put it in those variants. Other states then cannot access it, and the flow is easier to follow. Loop indexes belong in the variant too (ProcessingItem { idx, items }), advanced only when changing state.

Re-entrancy

When a call yields, the caller waits and then calls the function again from the top. Any state changed before the yield is changed again on the second call:

self.counter += 1;                          // runs on every re-entry
return_if_io!(something_that_might_yield());

Do the change after the yield returns, or move to a new state before yielding and make the change in that state:

return_if_io!(something_that_might_yield());
self.counter += 1;  // reached once

Typical bugs: vec.push(x), idx += 1, or map.insert(k, v) before a return_if_io! repeat on each re-entry.

Установить async-io-model в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл async-io-model?

Use when writing or changing code that returns IOResult or keeps I/O state across yields - state machines, re-entrancy, CompletionGroup

Как установить скилл async-io-model?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл async-io-model запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить async-io-model с