Commit 725e2d33 authored by Jeromy's avatar Jeromy

a little more correctness on the new bitswap impl

parent acd2765e
...@@ -98,7 +98,7 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er ...@@ -98,7 +98,7 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
// GetBlocks gets a list of blocks asynchronously and returns through // GetBlocks gets a list of blocks asynchronously and returns through
// the returned channel. // the returned channel.
// NB: No guarantees are made about order. // NB: No guarantees are made about order.
func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks.Block { func (s *BlockService) GetBlocks(parent context.Context, ks []u.Key) <-chan *blocks.Block {
out := make(chan *blocks.Block, 32) out := make(chan *blocks.Block, 32)
go func() { go func() {
var toFetch []u.Key var toFetch []u.Key
...@@ -112,11 +112,13 @@ func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks ...@@ -112,11 +112,13 @@ func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks
out <- block out <- block
} }
ctx, cancel := context.WithCancel(parent)
nblocks, err := s.Remote.GetBlocks(ctx, toFetch) nblocks, err := s.Remote.GetBlocks(ctx, toFetch)
if err != nil { if err != nil {
log.Errorf("Error with GetBlocks: %s", err) log.Errorf("Error with GetBlocks: %s", err)
return return
} }
for blk := range nblocks { for blk := range nblocks {
out <- blk out <- blk
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment