ITADN

Return async iterables from commands

#16190OpenRich-Harris 创建于 2026-06-26
R
Rich-Harriscommented
### Describe the problem If a `command` kicks off a long-running task, and you want to get progress updates, you basically have to return an ID and use that to call a `query.live`. It involves a bunch of book-keeping on both sides of the network divide. In some respects this is the right way to deal with it — you can use that live query in different contexts, and if it's a _really_ long running task then you can come back to it after navigating somewhere else — but for a lot of smaller jobs, being able to get progress reports directly from the command is the sweet spot. ### Describe the proposed solution Something like this — essentially, adding async iterables to the list of things that commands can return: ```js export const insertLargeThing = command(v.object(...), async function* (data) { yield { progress: 0 }; const task = startTask(data); while (!task.done) { yield { progress: task.progress }; await sleep(50); } }); ``` ```svelte <button onclick={async () => { for await (const task of insertLargeThing(...)) { progress = task.progress; } done = true; }} > insert large thing </button> ``` ### Alternatives considered not doing this ### Importance nice to have ### Additional Information _No response_
0 条评论