From d514b91ff3f15ad17152bff6f6fb0df3ef21140a Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Sun, 21 Sep 2014 22:06:12 -0700 Subject: [PATCH] fix(routing:dht) implement FindProvidersAsync in terms of FindProviders until construction is complete on the actual async method reverts changes from ec50703395098f75946f0bad01816cc54ab18a58 https://github.com/jbenet/go-ipfs/commit/ec50703395098f75946f0bad01816cc54ab18a58 --- routing/dht/routing.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/routing/dht/routing.go b/routing/dht/routing.go index 9f4a916e7..762a8cfd9 100644 --- a/routing/dht/routing.go +++ b/routing/dht/routing.go @@ -115,8 +115,26 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error { return nil } -// FindProvidersAsync runs FindProviders and sends back results over a channel +// NB: not actually async. Used to keep the interface consistent while the +// actual async method, FindProvidersAsync2 is under construction func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan *peer.Peer { + ch := make(chan *peer.Peer) + providers, err := dht.FindProviders(ctx, key) + if err != nil { + close(ch) + return ch + } + go func() { + defer close(ch) + for _, p := range providers { + ch <- p + } + }() + return ch +} + +// FIXME: there's a bug here! +func (dht *IpfsDHT) FindProvidersAsync2(ctx context.Context, key u.Key, count int) <-chan *peer.Peer { peerOut := make(chan *peer.Peer, count) go func() { ps := newPeerSet()