From 893f83367372c382e7f34879a04082240c9f7cbe Mon Sep 17 00:00:00 2001 From: nate smith Date: Tue, 29 Mar 2022 10:25:14 -0500 Subject: [PATCH] use errgroup --- pkg/cmd/status/status.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/status/status.go b/pkg/cmd/status/status.go index 944eef2a8..975a2329f 100644 --- a/pkg/cmd/status/status.go +++ b/pkg/cmd/status/status.go @@ -19,6 +19,7 @@ import ( "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/utils" "github.com/spf13/cobra" + "golang.org/x/sync/errgroup" ) type StatusOptions struct { @@ -516,39 +517,38 @@ func statusRun(opts *StatusOptions) error { } sg := NewStatusGetter(client, opts) - errc := make(chan error) // TODO break out sections into individual subcommands + g := new(errgroup.Group) opts.IO.StartProgressIndicator() - go func() { + g.Go(func() error { err := sg.LoadNotifications() if err != nil { err = fmt.Errorf("could not load notifications: %w", err) } - errc <- err - }() + return err + }) - go func() { + g.Go(func() error { err := sg.LoadEvents() if err != nil { err = fmt.Errorf("could not load events: %w", err) } - errc <- err - }() + return err + }) - go func() { + g.Go(func() error { err := sg.LoadSearchResults() if err != nil { err = fmt.Errorf("failed to search: %w", err) } - errc <- err - }() + return err + }) - for i := 0; i < 3; i++ { - if err := <-errc; err != nil { - return err - } + err = g.Wait() + if err != nil { + return err } opts.IO.StopProgressIndicator()