-
Notifications
You must be signed in to change notification settings - Fork 351
Open
Description
There are tasks where not having a result is not the error case. For these cases I propose extending the set of Pools with
type OptionalResultPool[T any] struct {}
func (p *OptionalResultPool[T]) Go(f func() *T) {}
func (p *OptionalResultPool[T]) Wait() []T {}
type OptionalResultErrorPool[T any] struct {
func (p *OptionalResultErrorPool[T]) Go(f func() (*T, error)) {}
func (p *OptionalResultErrorPool[T]) Wait() ([]T, error) {}
type OptionalResultContextPool[T any] struct {}
func (p *OptionalResultContextPool[T]) Go(f func(context.Context) (*T, error)) {}
func (p *OptionalResultContextPool[T]) Wait() ([]T, error) {}Wait() would then discard all nil results without an error and dereference the pointers.
The alternative to this that I am currently using is a wrapper type, that I then filter and map to the original type, but a native solution would be preferable.
Should I open a PR for this?
Metadata
Metadata
Assignees
Labels
No labels