Skip to content

Commit d514b91

Browse files
author
Brian Tiger Chow
committed
fix(routing:dht) implement FindProvidersAsync in terms of FindProviders
until construction is complete on the actual async method reverts changes from ec50703 ec50703
1 parent 39ad222 commit d514b91

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

routing/dht/routing.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,26 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
115115
return nil
116116
}
117117

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
119120
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 {
120138
peerOut := make(chan *peer.Peer, count)
121139
go func() {
122140
ps := newPeerSet()

0 commit comments

Comments
 (0)