Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit f19a34a

Browse files
committed
fix: pass a context to PinsStream
1 parent 0f69d97 commit f19a34a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

shell.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ type PinStreamInfo struct {
245245

246246
// PinsStream is a streamed version of Pins. It returns a channel of the pins
247247
// with their type, one of DirectPin, RecursivePin, or IndirectPin.
248-
func (s *Shell) PinsStream() (<-chan PinStreamInfo, error) {
248+
func (s *Shell) PinsStream(ctx context.Context) (<-chan PinStreamInfo, error) {
249249
resp, err := s.Request("pin/ls").
250250
Option("stream", true).
251-
Send(context.Background())
251+
Send(ctx)
252252
if err != nil {
253253
return nil, err
254254
}
@@ -269,7 +269,11 @@ func (s *Shell) PinsStream() (<-chan PinStreamInfo, error) {
269269
if err != nil {
270270
return
271271
}
272-
out <- pin
272+
select {
273+
case out <- pin:
274+
case <-ctx.Done():
275+
return
276+
}
273277
}
274278
}()
275279

shell_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func TestPinsStream(t *testing.T) {
247247
h, err := s.Add(bytes.NewBufferString("go-ipfs-api pins test 0C7023F8-1FEC-4155-A8E0-432A5853F46B"))
248248
is.Nil(err)
249249

250-
pinChan, err := s.PinsStream()
250+
pinChan, err := s.PinsStream(context.Background())
251251
is.Nil(err)
252252

253253
pins := accumulatePins(pinChan)
@@ -258,7 +258,7 @@ func TestPinsStream(t *testing.T) {
258258
err = s.Unpin(h)
259259
is.Nil(err)
260260

261-
pinChan, err = s.PinsStream()
261+
pinChan, err = s.PinsStream(context.Background())
262262
is.Nil(err)
263263

264264
pins = accumulatePins(pinChan)
@@ -269,7 +269,7 @@ func TestPinsStream(t *testing.T) {
269269
err = s.Pin(h)
270270
is.Nil(err)
271271

272-
pinChan, err = s.PinsStream()
272+
pinChan, err = s.PinsStream(context.Background())
273273
is.Nil(err)
274274

275275
pins = accumulatePins(pinChan)

0 commit comments

Comments
 (0)