badger/AllKeysChan(): respect context.

This commit is contained in:
Raúl Kripalani 2020-11-11 23:12:16 +00:00
parent 6f593d53d0
commit 04a866121e

View File

@ -359,7 +359,11 @@ func (b *Blockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
buf = make([]byte, reqlen) buf = make([]byte, reqlen)
} }
if n, err := base32.RawStdEncoding.Decode(buf, k); err == nil { if n, err := base32.RawStdEncoding.Decode(buf, k); err == nil {
ch <- cid.NewCidV1(cid.Raw, buf[:n]) select {
case ch <- cid.NewCidV1(cid.Raw, buf[:n]):
case <-ctx.Done():
return
}
} else { } else {
log.Warnf("failed to decode key %s in badger AllKeysChan; err: %s", k, err) log.Warnf("failed to decode key %s in badger AllKeysChan; err: %s", k, err)
} }