Skip to content

Commit

Permalink
Break fors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnavarro committed Aug 26, 2022
1 parent 6a35764 commit 665ea8f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions composable/sequential.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func (r *Sequential) FindProvidersAsync(ctx context.Context, cid cid.Cid, count
return
case v, ok := <-rch:
if !ok {
break
return
}
if sentCount >= count {
break
return
}

chanOut <- v
Expand Down Expand Up @@ -167,22 +167,25 @@ func (r *Sequential) SearchValue(ctx context.Context, key string, opts ...routin

go func() {
for i := 0; i < len(chans); i++ {
defer cancels[i]()
if chans[i] == nil {
cancels[i]()
continue
}

forr:
for {
select {
case <-ctx.Done():
return
case v, ok := <-chans[i]:
if !ok {
break
break forr
}
chanOut <- v
}
}

cancels[i]()
}
}()

Expand Down

0 comments on commit 665ea8f

Please sign in to comment.