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

Return chan struct{} from pool.Stop() to give a better control over cleanup operations. #63

Open
CorentinClabaut opened this issue Jun 7, 2024 · 0 comments

Comments

@CorentinClabaut
Copy link
Collaborator

Currently, when calling pool.Stop(), there's no immediate way to know when the pool has completely halted its operations.

By adding a chan struct{} return type to pool.Stop(), users can receive a signal indicating when the pool has stopped, enabling better management of resources and cleanup tasks.

This enhancement would help when multiple concurrent cleanup tasks need to be executed within a predefined timeframe.

	ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
	defer cancel()

        poolStopped := pool.Stop()
        otherStopped := other.Stop()

	select {
	case <-poolStopped:
	case <-ctx.Done():
		log.Error("Worker pool did not stop gracefully")
	}
	
        select {
	case <-otherStopped:
	case <-ctx.Done():
		log.Error("other did not stop gracefully")
	}

Let me know if you think that would be a good addition, and if so, I can create a pull request for it.

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