Преглед изворни кода

util/singleflight: sync with upstream

Sync with golang.org/x/sync/singleflight at commit
8fcdb60fdcc0539c5e357b2308249e4e752147f1

Fixes #5790

Signed-off-by: Cuong Manh Le <[email protected]>
Cuong Manh Le пре 3 година
родитељ
комит
a7efc7bd17
1 измењених фајлова са 2 додато и 9 уклоњено
  1. 2 9
      util/singleflight/singleflight.go

+ 2 - 9
util/singleflight/singleflight.go

@@ -65,10 +65,6 @@ type call[V any] struct {
 	val V
 	err error
 
-	// forgotten indicates whether Forget was called with this call's key
-	// while the call was still in flight.
-	forgotten bool
-
 	// These fields are read and written with the singleflight
 	// mutex held before the WaitGroup is done, and are read but
 	// not written after the WaitGroup is done.
@@ -161,10 +157,10 @@ func (g *Group[K, V]) doCall(c *call[V], key K, fn func() (V, error)) {
 			c.err = errGoexit
 		}
 
-		c.wg.Done()
 		g.mu.Lock()
 		defer g.mu.Unlock()
-		if !c.forgotten {
+		c.wg.Done()
+		if g.m[key] == c {
 			delete(g.m, key)
 		}
 
@@ -217,9 +213,6 @@ func (g *Group[K, V]) doCall(c *call[V], key K, fn func() (V, error)) {
 // an earlier call to complete.
 func (g *Group[K, V]) Forget(key K) {
 	g.mu.Lock()
-	if c, ok := g.m[key]; ok {
-		c.forgotten = true
-	}
 	delete(g.m, key)
 	g.mu.Unlock()
 }