This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -245,10 +245,10 @@ type PinStreamInfo struct {
245
245
246
246
// PinsStream is a streamed version of Pins. It returns a channel of the pins
247
247
// 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 ) {
249
249
resp , err := s .Request ("pin/ls" ).
250
250
Option ("stream" , true ).
251
- Send (context . Background () )
251
+ Send (ctx )
252
252
if err != nil {
253
253
return nil , err
254
254
}
@@ -269,7 +269,11 @@ func (s *Shell) PinsStream() (<-chan PinStreamInfo, error) {
269
269
if err != nil {
270
270
return
271
271
}
272
- out <- pin
272
+ select {
273
+ case out <- pin :
274
+ case <- ctx .Done ():
275
+ return
276
+ }
273
277
}
274
278
}()
275
279
Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ func TestPinsStream(t *testing.T) {
247
247
h , err := s .Add (bytes .NewBufferString ("go-ipfs-api pins test 0C7023F8-1FEC-4155-A8E0-432A5853F46B" ))
248
248
is .Nil (err )
249
249
250
- pinChan , err := s .PinsStream ()
250
+ pinChan , err := s .PinsStream (context . Background () )
251
251
is .Nil (err )
252
252
253
253
pins := accumulatePins (pinChan )
@@ -258,7 +258,7 @@ func TestPinsStream(t *testing.T) {
258
258
err = s .Unpin (h )
259
259
is .Nil (err )
260
260
261
- pinChan , err = s .PinsStream ()
261
+ pinChan , err = s .PinsStream (context . Background () )
262
262
is .Nil (err )
263
263
264
264
pins = accumulatePins (pinChan )
@@ -269,7 +269,7 @@ func TestPinsStream(t *testing.T) {
269
269
err = s .Pin (h )
270
270
is .Nil (err )
271
271
272
- pinChan , err = s .PinsStream ()
272
+ pinChan , err = s .PinsStream (context . Background () )
273
273
is .Nil (err )
274
274
275
275
pins = accumulatePins (pinChan )
You can’t perform that action at this time.
0 commit comments