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
Brian Tiger Chow committed
Sep 21, 2014 at 22:06 UTC
d514b91ff3f15ad17152bff6f6fb0df3ef21140a
1 file changed
+19
-1
routing/dht/routing.go
+19
-1
@@ -115,8 +115,26 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
115
return nil
116
}
117
118
-// FindProvidersAsync runs FindProviders and sends back results over a channel
118
+// NB: not actually async. Used to keep the interface consistent while the
119
+// actual async method, FindProvidersAsync2 is under construction
120
func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan *peer.Peer {
121
+ ch := make(chan *peer.Peer)
122
+ providers, err := dht.FindProviders(ctx, key)
123
+ if err != nil {
124
+ close(ch)
125
+ return ch
126
+ }
127
+ go func() {
128
+ defer close(ch)
129
+ for _, p := range providers {
130
+ ch <- p
131
+ }
132
+ }()
133
+ return ch
134
+}
135
+
136
+// FIXME: there's a bug here!
137
+func (dht *IpfsDHT) FindProvidersAsync2(ctx context.Context, key u.Key, count int) <-chan *peer.Peer {
138
peerOut := make(chan *peer.Peer, count)
139
go func() {
140
ps := newPeerSet()