Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
corverroos committed Apr 23, 2023
1 parent e0dea65 commit 7393ae4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/eth2wrap/eth2wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ func (m multi) NodePeerCount(ctx context.Context) (int, error) {
// first successful result or first error.
// The bestIdxFunc is called with the index of the client returning a successful response.
func provide[O any](ctx context.Context, clients []Client,
work forkjoin.Work[Client, O], isSuccess func(O) bool, bestIdxFunc func(int),
work forkjoin.Work[Client, O], isSuccessFunc func(O) bool, bestIdxFunc func(int),
) (O, error) {
if isSuccess == nil {
isSuccess = func(O) bool { return true }
if isSuccessFunc == nil {
isSuccessFunc = func(O) bool { return true }
}
if bestIdxFunc == nil {
bestIdxFunc = func(int) {}
}

fork, join, cancel := forkjoin.New(ctx, work,
Expand All @@ -248,7 +251,7 @@ func provide[O any](ctx context.Context, clients []Client,
for res := range join() {
if ctx.Err() != nil {
return zero, ctx.Err()
} else if res.Err == nil && isSuccess(res.Output) {
} else if res.Err == nil && isSuccessFunc(res.Output) {
// TODO(corver): Find a better way to get the index of successful client.
for i, client := range clients {
if client.Address() == res.Input.Address() {
Expand Down

0 comments on commit 7393ae4

Please sign in to comment.