Questions about Asynchronous Communication Feature in GoTask

Open
#66 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
go
Domain
backend

Research direction

Start with the gotask.Register and gotask.Run entry points shown in the example, then inspect the package for any existing task result or communication APIs. Determine whether partial updates are currently supported and document the relevant usage, or define the scope of a new asynchronous communication feature. No specific files or tests are named in the issue.

Written by the indexing model from the issue text.

Description

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!

Dominant language
PHP
Stars
255
Forks
29
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hyperf/gotask

All issues in hyperf/gotask

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.