developit / developit/task-worklet
Long running tasks
- Dominant language
- JavaScript
- Stars
- 278
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
The `postTask` API is request/response based, and as such doesn't have a natural fit for long running tasks. How do you see such tasks fitting into the model?
For example, let's say I had a worklet which connects to a chat service (via http2 or websocket) and receives chat messages. Currently you could poll the worklet for the next message like so:
```js
const queue = new TaskQueue();
async function run() {
await queue.addModule('/chat-worklet.js');
while(true) {
const task = queue.postTask('nextMessage');
const message = await task.result;
addChatMessageToList(message);
}
}
run();
```
I guess this is ok but it also doesn't seem ideal to me. I think it would make the worklet side more complex in a lot of cases (you might have to keep some global state to know which messages have been sent to which requester).
It would be nice if tasks could also return a stream or something, so that you could use `for/of` to await each message.
Contributor guide
Research direction
Start with the postTask API and the polling example in this issue. Compare the proposed stream or for/of behavior with the current request/response model, including how long-lived connections and requester state would be handled. Done means the project has an agreed approach for long-running tasks; no file or test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100