Skip to content

Commit

Permalink
replace waitGrp with errGrp
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Mar 12, 2024
1 parent 78c92b9 commit bb78245
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions cli/filplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"os"
"strconv"
"strings"
"sync"

"github.com/chzyer/readline"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
Expand Down Expand Up @@ -1087,36 +1087,24 @@ var filplusExtendClaimCmd = &cli.Command{
}

// wait for msgs to get mined into a block
var wg sync.WaitGroup
wg.Add(len(smsgs))
results := make(chan error, len(smsgs))
eg := errgroup.Group{}
eg.SetLimit(10)
for _, msg := range smsgs {
m := msg

This comment has been minimized.

Copy link
@snadrus

snadrus Mar 13, 2024

Collaborator

msg := msg
And we prefer xerrors.Errorf() because we get call-site info instead of just the messages.

go func() {
defer wg.Done()
eg.Go(func() error {
wait, err := api.StateWaitMsg(ctx, m.Cid(), uint64(cctx.Int("confidence")))
if err != nil {
results <- xerrors.Errorf("Timeout waiting for message to land on chain %s", wait.Message)
return
return fmt.Errorf("timeout waiting for message to land on chain %s", wait.Message)

}

if wait.Receipt.ExitCode.IsError() {
results <- fmt.Errorf("failed to execute message %s: %w", wait.Message, wait.Receipt.ExitCode)
return
return fmt.Errorf("failed to execute message %s: %w", wait.Message, wait.Receipt.ExitCode)
}
results <- nil
}()
}

wg.Wait()
close(results)

for res := range results {
if res != nil {
fmt.Println("Failed to execute the message %w", res)
}
return nil
})
}
return nil
return eg.Wait()
},
}

Expand Down

0 comments on commit bb78245

Please sign in to comment.