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

group: panic when submitting zero tasks #78

Closed
mastercactapus opened this issue Oct 28, 2024 · 1 comment · Fixed by #79
Closed

group: panic when submitting zero tasks #78

mastercactapus opened this issue Oct 28, 2024 · 1 comment · Fixed by #79

Comments

@mastercactapus
Copy link

mastercactapus commented Oct 28, 2024

This behavior seems to be intentional, so I'm curious if there's an implementation reason why this isn't allowed?

Here's an example:

var tasks []func() Rule
for _, rule := range matchingRules {
	if rule.Disabled {
		continue
	}
	tasks = append(tasks, func() Rule {
		return lookupRule(ctx, rule, body)
	})
}

// panic if len(tasks) == 0, rather than returning `nil, nil`
return ruleLookupPool.NewGroup().Submit(tasks...).Wait()

It's easy enough to do a length check first but it was a bit unexpected -- I expected to get an empty slice back.


That said, I'm guessing the expected pattern is to call Submit multiple times instead and will update my code as such -- but thought I'd raise the issue in case there's any additional context around it.

@alitto
Copy link
Owner

alitto commented Oct 29, 2024

Hey @mastercactapus, thanks for bringing this up!

I agree the panic in this situation is a bit unexpected. I opened a PR to remove the panic and return an empty slice + a nil error in this case. This fix is released in https://github.com/alitto/pond/releases/tag/v2.0.4

Cheers!

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

Successfully merging a pull request may close this issue.

2 participants