Questions about Asynchronous Communication Feature in GoTask

未关闭
#66 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
go
领域
backend

调研方向

从示例中展示的 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

  1. Does the gotask package already include the functionality for asynchronous communication?
  2. If yes, how can I use this functionality to receive updates or partial results from Go tasks while they are being processed?
  3. 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hyperf/gotask 的其他 Issue

查看 hyperf/gotask 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。