developit / developit/task-worklet
Long running tasks
- 主要语言
- JavaScript
- 星标
- 278
- 派生
- 4
- PR 合并指标
- 30 天内没有已合并 PR
描述
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.
贡献指南
调研方向
从此 issue 中的 postTask API 和 polling 示例开始。将提议的 stream 或 for/of 行为与当前的 request/response 模型进行比较,包括如何处理长连接和 requester 状态。完成的标准是项目就长时间运行的任务达成一致的方案;issue 中没有指定文件或测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- web-dev
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100