Questions about Asynchronous Communication Feature in GoTask
还没有人认领这个 Issue。
评估
调研方向
从示例中展示的 gotask.Register 和 gotask.Run 入口点开始,然后检查 package 中是否已有用于任务结果或通信的 API。确定当前是否支持部分更新,并记录相关用法,或定义新的异步通信功能的范围。Issue 中未指定具体文件或测试。
由索引模型根据 Issue 内容生成。
描述
Description
Problem Description:
I'm exploring the usage of the gotask package in my project and I'm encountering a scenario where I need to execute heavy processes using Go tasks. However, I'm looking for a feature that allows asynchronous communication between the code triggering the Go tasks and the tasks themselves. This feature would enable me to receive partial results or updates from the process as it progresses, similar to a "yield" mechanism in asynchronous languages.
Question
- Does the gotask package already include the functionality for asynchronous communication?
- If yes, how can I use this functionality to receive updates or partial results from Go tasks while they are being processed?
- If the functionality doesn't exist, do you have any suggestions or tips on how I can implement this type of asynchronous communication in conjunction with the gotask package?
Examples
If possible, I would appreciate seeing examples of how this functionality can be implemented, whether by using existing features within the gotask package or through suggestions on extending the code to achieve this goal. Below is an example of what I have in mind:
package main
import (
"log"
"time"
"github.com/hyperf/gotask/v2/pkg/gotask"
)
// App sample
type App struct{}
// ProcessBatch executes batch processing and sends asynchronous updates.
func (a *App) ProcessBatch(input interface{}, r *string) error {
for i := 1; i <= 10; i++ {
// Simulating heavy processing
time.Sleep(1 * time.Second)
// Sending asynchronous update
gotask.AsyncUpdate(fmt.Sprintf("Processed %d items", i))
}
*r = "Processing completed"
return nil
}
func main() {
if err := gotask.Register(new(App)); err != nil {
log.Fatalln(err)
}
if err := gotask.Run(); err != nil {
log.Fatalln(err)
}
}
Benefits
Implementing this asynchronous communication feature between Go tasks and the triggering code would open up new possibilities for utilizing the gotask package. Furthermore, this feature would enhance the utility of the library for heavy processing scenarios.
Thank you in advance for your attention and assistance!
- 主要语言
- PHP
- 星标
- 255
- 派生
- 29
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
hyperf/gotask 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 20/100
-
这个项目还维护吗未关闭
难度 5/5 一周以上 新手友好度 15/100
-
gotask是不支持协程风格吗?未关闭
难度 4/5 3-5 天 新手友好度 35/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 3 天内回复
-
难度 1/5 1 小时以内 新手友好度 91/100
benjaminkott/bootstrap_package#1675 ·
-
sync-en
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复