Skip to content

Commit a366d8b

Browse files
committed
address reviews
1 parent 07285de commit a366d8b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

dht_options.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"time"
66

7-
"github.com/ipfs/go-ipns"
8-
97
ds "github.com/ipfs/go-datastore"
108
dssync "github.com/ipfs/go-datastore/sync"
119
"github.com/ipfs/go-ipns"

dual/dual.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,26 @@ func (dht *DHT) PutValue(ctx context.Context, key string, val []byte, opts ...ro
174174

175175
// GetValue searches for the value corresponding to given Key.
176176
func (d *DHT) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error) {
177-
reqCtx, cncl := context.WithCancel(ctx)
178-
defer cncl()
177+
lanCtx, cancelLan := context.WithCancel(ctx)
178+
defer cancelLan()
179179

180-
var lanVal []byte
181-
var lanErr error
182-
var lanWaiter sync.WaitGroup
180+
var (
181+
lanVal []byte
182+
lanErr error
183+
lanWaiter sync.WaitGroup
184+
)
183185
lanWaiter.Add(1)
184186
go func() {
185187
defer lanWaiter.Done()
186-
lanVal, lanErr = d.LAN.GetValue(reqCtx, key, opts...)
188+
lanVal, lanErr = d.LAN.GetValue(lanCtx, key, opts...)
187189
}()
188190

189191
wanVal, wanErr := d.WAN.GetValue(ctx, key, opts...)
192+
if wanErr == nil {
193+
cancelLan()
194+
}
195+
lanWaiter.Wait()
190196
if wanErr != nil {
191-
lanWaiter.Wait()
192197
if lanErr != nil {
193198
return nil, multierror.Append(wanErr, lanErr).ErrorOrNil()
194199
}

0 commit comments

Comments
 (0)