I'm trying to generalize the use of errgroup in my code, but while doing so I'm failing to assign the return:
func getAsync[U any](ctx context.Context, asyncGroup *errgroup.Group, argument int64, ex executor[U], result *U) {
asyncGroup.Go(func() (err error) {
result, err = ex(ctx, argument)
return
})
}
type executor[U any] func(ctx context.Context, argument int64) (*U, error)
func myFunc(ctx context.Context, id int64) {
var myPointer *domain.MyDomain
group, _ := errgroup.WithContext(ctx)
getAsync[domain.MyDomain](ctx, group, id, service.GetMyDomain, &myPointer)
err := group.Wait()
...
}
Doing so, the variable myPointer is null after the call even so the executor returns successfully.
Function GetMyDomain has the following signature:
func GetMyDomain(ctx context.Context, id int64) (*domain.MyDomain, error)