diff --git a/hamt/hamt.go b/hamt/hamt.go index a823fa301..3714c30a2 100644 --- a/hamt/hamt.go +++ b/hamt/hamt.go @@ -29,9 +29,8 @@ import ( cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" dag "github.com/ipfs/go-merkledag" - "github.com/spaolacci/murmur3" - format "github.com/ipfs/go-unixfs" + "github.com/spaolacci/murmur3" ) const ( @@ -401,10 +400,8 @@ func (ds *Shard) getValue(ctx context.Context, hv *hashBits, key string, cb func func (ds *Shard) EnumLinks(ctx context.Context) ([]*ipld.Link, error) { var links []*ipld.Link - linkResults, err := ds.EnumLinksAsync(ctx) - if err != nil { - return nil, err - } + linkResults := ds.EnumLinksAsync(ctx) + for linkResult := range linkResults { if linkResult.Err != nil { return links, linkResult.Err @@ -426,7 +423,7 @@ func (ds *Shard) ForEachLink(ctx context.Context, f func(*ipld.Link) error) erro // EnumLinksAsync returns a channel which will receive Links in the directory // as they are enumerated, where order is not gauranteed -func (ds *Shard) EnumLinksAsync(ctx context.Context) (<-chan format.LinkResult, error) { +func (ds *Shard) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult { linkResults := make(chan format.LinkResult) ctx, cancel := context.WithCancel(ctx) go func() { @@ -439,7 +436,7 @@ func (ds *Shard) EnumLinksAsync(ctx context.Context) (<-chan format.LinkResult, emitResult(ctx, linkResults, format.LinkResult{Link: nil, Err: err}) } }() - return linkResults, nil + return linkResults } // makeAsyncTrieGetLinks builds a getLinks function that can be used with EnumerateChildrenAsync diff --git a/hamt/hamt_test.go b/hamt/hamt_test.go index 077976051..1483fcd9f 100644 --- a/hamt/hamt_test.go +++ b/hamt/hamt_test.go @@ -337,10 +337,8 @@ func TestEnumLinksAsync(t *testing.T) { t.Fatal(err) } - linkResults, err := nds.EnumLinksAsync(ctx) - if err != nil { - t.Fatal(err) - } + linkResults := nds.EnumLinksAsync(ctx) + var linksB []*ipld.Link for linkResult := range linkResults { diff --git a/io/directory.go b/io/directory.go index 5a4f638b9..2e0227623 100644 --- a/io/directory.go +++ b/io/directory.go @@ -41,7 +41,7 @@ type Directory interface { // EnumLinksAsync returns a channel which will receive Links in the directory // as they are enumerated, where order is not gauranteed - EnumLinksAsync(context.Context) (<-chan format.LinkResult, error) + EnumLinksAsync(context.Context) <-chan format.LinkResult // Links returns the all the links in the directory node. Links(context.Context) ([]*ipld.Link, error) @@ -148,7 +148,7 @@ func (d *BasicDirectory) AddChild(ctx context.Context, name string, node ipld.No // EnumLinksAsync returns a channel which will receive Links in the directory // as they are enumerated, where order is not gauranteed -func (d *BasicDirectory) EnumLinksAsync(ctx context.Context) (<-chan format.LinkResult, error) { +func (d *BasicDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult { linkResults := make(chan format.LinkResult) go func() { defer close(linkResults) @@ -163,7 +163,7 @@ func (d *BasicDirectory) EnumLinksAsync(ctx context.Context) (<-chan format.Link } } }() - return linkResults, nil + return linkResults } // ForEachLink implements the `Directory` interface. @@ -253,7 +253,7 @@ func (d *HAMTDirectory) ForEachLink(ctx context.Context, f func(*ipld.Link) erro // EnumLinksAsync returns a channel which will receive Links in the directory // as they are enumerated, where order is not gauranteed -func (d *HAMTDirectory) EnumLinksAsync(ctx context.Context) (<-chan format.LinkResult, error) { +func (d *HAMTDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult { return d.shard.EnumLinksAsync(ctx) } diff --git a/io/directory_test.go b/io/directory_test.go index 6f621e977..12c481753 100644 --- a/io/directory_test.go +++ b/io/directory_test.go @@ -158,10 +158,7 @@ func TestDirBuilder(t *testing.T) { t.Fatal("wrong number of links", len(links), count) } - linkResults, err := dir.EnumLinksAsync(ctx) - if err != nil { - t.Fatal(err) - } + linkResults := dir.EnumLinksAsync(ctx) asyncNames := make(map[string]bool) var asyncLinks []*ipld.Link