Return async iterables from commands
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
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:
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);
}
});
<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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how commands are currently invoked and how their return values cross the network boundary; the issue does not name specific files or tests. Define the async-iterable behavior for progress values, completion, and the client-side for-await usage, then add coverage for the proposed command and Svelte examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100