Skip to content

Commit 665ea8f

Browse files
committed
Break fors correctly
1 parent 6a35764 commit 665ea8f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

composable/sequential.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func (r *Sequential) FindProvidersAsync(ctx context.Context, cid cid.Cid, count
5656
return
5757
case v, ok := <-rch:
5858
if !ok {
59-
break
59+
return
6060
}
6161
if sentCount >= count {
62-
break
62+
return
6363
}
6464

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

168168
go func() {
169169
for i := 0; i < len(chans); i++ {
170-
defer cancels[i]()
171170
if chans[i] == nil {
171+
cancels[i]()
172172
continue
173173
}
174174

175+
forr:
175176
for {
176177
select {
177178
case <-ctx.Done():
178179
return
179180
case v, ok := <-chans[i]:
180181
if !ok {
181-
break
182+
break forr
182183
}
183184
chanOut <- v
184185
}
185186
}
187+
188+
cancels[i]()
186189
}
187190
}()
188191

0 commit comments

Comments
 (0)