Skip to content

Commit d2a98c9

Browse files
committed
rename call.dups to call.refCount
1 parent 4eee079 commit d2a98c9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

singleflight/singleflight.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type call struct {
2424
// These fields are read and written with the singleflight
2525
// mutex held before the WaitGroup is done, and are read but
2626
// not written after the WaitGroup is done.
27-
dups int
28-
chans []chan<- Result
27+
refCount int64
28+
chans []chan<- Result
2929
}
3030

3131
// Group represents a class of work and forms a namespace in
@@ -62,12 +62,12 @@ func (g *Group) DoChan(key string, fn func() (interface{}, error)) <-chan Result
6262
g.m = make(map[string]*call)
6363
}
6464
if c, ok := g.m[key]; ok {
65-
c.dups++
65+
c.refCount++
6666
c.chans = append(c.chans, ch)
6767
g.mu.Unlock()
6868
return ch
6969
}
70-
c := &call{chans: []chan<- Result{ch}}
70+
c := &call{refCount: 1, chans: []chan<- Result{ch}}
7171
c.wg.Add(1)
7272
g.m[key] = c
7373
g.mu.Unlock()
@@ -87,7 +87,7 @@ func (g *Group) doCall(c *call, key string, fn func() (interface{}, error)) {
8787
delete(g.m, key)
8888
}
8989
for _, ch := range c.chans {
90-
ch <- Result{c.val, c.err, c.dups > 0}
90+
ch <- Result{c.val, c.err, c.refCount > 1}
9191
}
9292
g.mu.Unlock()
9393
}

0 commit comments

Comments
 (0)