Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add "Join" functionality to the group #59

Open
opengs opened this issue May 27, 2024 · 1 comment
Open

Feature request: Add "Join" functionality to the group #59

opengs opened this issue May 27, 2024 · 1 comment

Comments

@opengs
Copy link

opengs commented May 27, 2024

Problem

I am running an application that consistently operates with a specific number of workers. Additionally, when a worker discovers work, it requires a boost from the pool. To achieve this, a limited shared pool for boosting is necessary.

Proposed Feature

The idea is to introduce a Join functionality to the Group, enabling the current goroutine not only to wait for all tasks in the group to complete but also to assist in executing the tasks within it. So the general flow is:

  • When a goroutine calls Join on a Group, it becomes part of the execution pool for that group.
  • The goroutine waits for all tasks within the group to finish, actively participating in executing these tasks rather than idly waiting.

Example

package main

import (
	"fmt"

	"github.com/alitto/pond"
)

func main() {

	// Create a pool
	pool := pond.New(10, 1000)
	defer pool.StopAndWait()

	// Create a task group
	group := pool.Group()

	// Submit a group of tasks
	for i := 0; i < 20; i++ {
		n := i
		group.Submit(func() {
			fmt.Printf("Running group task #%d\n", n)
		})
	}

	// Join pool for this group and help for all tasks in the group to complete
	group.Join()
}

Other

Maybe for consistency this functionality also should be added to the WorkerPool object itself, but I cant imagine situation where it can be needed.

@opengs opengs changed the title Feature request: Add "Join" functionality to pool group Feature request: Add "Join" functionality to the group May 27, 2024
@opengs
Copy link
Author

opengs commented May 27, 2024

I think ability to limit the size of the WorkGroup can also solve the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant