Sync with golang.org/x/sync/singleflight at commit 8fcdb60fdcc0539c5e357b2308249e4e752147f1 Fixes #5790 Signed-off-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
@ -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 {
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) {
if c, ok := g.m[key]; ok {
c.forgotten = true
g.mu.Unlock()