From 24aa42d85d10ca858ba0f8ea0e54ec6151cf3fb4 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 30 Nov 2016 17:45:17 -0500 Subject: [PATCH] blockstore.AllKeyChan: avoid channels by using the new NextSync method License: MIT Signed-off-by: Kevin Atkinson --- blocks/blockstore/blockstore.go | 39 ++++++++++----------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/blocks/blockstore/blockstore.go b/blocks/blockstore/blockstore.go index 9e5d8ca80..d5a77ab23 100644 --- a/blocks/blockstore/blockstore.go +++ b/blocks/blockstore/blockstore.go @@ -181,44 +181,27 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) return nil, err } - // this function is here to compartmentalize - get := func() (*cid.Cid, bool) { - select { - case <-ctx.Done(): - return nil, false - case e, more := <-res.Next(): - if !more { - return nil, false - } - if e.Error != nil { - log.Debug("blockstore.AllKeysChan got err:", e.Error) - return nil, false - } - - // need to convert to key.Key using key.KeyFromDsKey. - c, err := dshelp.DsKeyToCid(ds.RawKey(e.Key)) - if err != nil { - log.Warningf("error parsing key from DsKey: ", err) - return nil, true - } - - return c, true - } - } - output := make(chan *cid.Cid, dsq.KeysOnlyBufSize) go func() { defer func() { - res.Process().Close() // ensure exit (signals early exit, too) + res.Close() // ensure exit (signals early exit, too) close(output) }() for { - k, ok := get() + e, ok := res.NextSync() if !ok { return } - if k == nil { + if e.Error != nil { + log.Debug("blockstore.AllKeysChan got err:", e.Error) + continue + } + + // need to convert to key.Key using key.KeyFromDsKey. + k, err := dshelp.DsKeyToCid(ds.RawKey(e.Key)) + if err != nil { + log.Warningf("error parsing key from DsKey: ", err) continue }