Skip to content

Commit 6a35764

Browse files
committed
Check context on channel iteration
1 parent 4a44123 commit 6a35764

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

composable/sequential.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ func (r *Sequential) FindProvidersAsync(ctx context.Context, cid cid.Cid, count
5050
g.Add(1)
5151
go func() {
5252
defer g.Done()
53-
for addr := range rch {
54-
if sentCount >= count {
55-
break
53+
for {
54+
select {
55+
case <-ctx.Done():
56+
return
57+
case v, ok := <-rch:
58+
if !ok {
59+
break
60+
}
61+
if sentCount >= count {
62+
break
63+
}
64+
65+
chanOut <- v
66+
sentCount++
5667
}
57-
58-
chanOut <- addr
59-
sentCount++
6068
}
6169
}()
6270

0 commit comments

Comments
 (0)