]> Cypherpunks repositories - gostls13.git/commitdiff
internal/singleflight: make DoChan only return Result channel
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 13 Aug 2022 17:35:24 +0000 (00:35 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 24 Aug 2022 02:54:32 +0000 (02:54 +0000)
So next CL can delete "internal/singleflight" and vendor
"golang.org/x/sync/singleflight" instead.

For #31697

Change-Id: I020da1e5a48d484637b538c010029218f5a4a744
Reviewed-on: https://go-review.googlesource.com/c/go/+/423655
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/internal/singleflight/singleflight.go
src/net/lookup.go

index 07b3f40ec03d46465813d73c33272a4ed01b65e4..19d5a94a0bba2a6d8795bfd716016a67ae85bb30 100644 (file)
@@ -65,10 +65,8 @@ func (g *Group) Do(key string, fn func() (any, error)) (v any, err error, shared
 }
 
 // DoChan is like Do but returns a channel that will receive the
-// results when they are ready. The second result is true if the function
-// will eventually be called, false if it will not (because there is
-// a pending request with this key).
-func (g *Group) DoChan(key string, fn func() (any, error)) (<-chan Result, bool) {
+// results when they are ready.
+func (g *Group) DoChan(key string, fn func() (any, error)) <-chan Result {
        ch := make(chan Result, 1)
        g.mu.Lock()
        if g.m == nil {
@@ -78,7 +76,7 @@ func (g *Group) DoChan(key string, fn func() (any, error)) (<-chan Result, bool)
                c.dups++
                c.chans = append(c.chans, ch)
                g.mu.Unlock()
-               return ch, false
+               return ch
        }
        c := &call{chans: []chan<- Result{ch}}
        c.wg.Add(1)
@@ -87,7 +85,7 @@ func (g *Group) DoChan(key string, fn func() (any, error)) (<-chan Result, bool)
 
        go g.doCall(c, key, fn)
 
-       return ch, true
+       return ch
 }
 
 // doCall handles the single call for a key.
index 3cc53f1db6857b0401c30ac40b8fc33709af3fc4..b283c679454846ab2d732c16989344a86bb38a6a 100644 (file)
@@ -316,7 +316,7 @@ func (r *Resolver) lookupIPAddr(ctx context.Context, network, host string) ([]IP
 
        lookupKey := network + "\000" + host
        dnsWaitGroup.Add(1)
-       ch, _ := r.getLookupGroup().DoChan(lookupKey, func() (any, error) {
+       ch := r.getLookupGroup().DoChan(lookupKey, func() (any, error) {
                return testHookLookupIP(lookupGroupCtx, resolverFunc, network, host)
        })