Skip to content

Commit 682143f

Browse files
committed
refShared -> exported RefShared
1 parent 8b166cb commit 682143f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

singleflight/singleflight.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,24 @@ type Group struct {
4141
type Result struct {
4242
Val interface{}
4343
Err error
44-
Shared refShared
44+
Shared RefShared
4545
}
4646

4747
// this encapsulates both "shared boolean" as well as actual reference counter
48-
// callers can call refShared.Decrement to determine when last caller is done using result, so cleanup if needed can be performed
49-
type refShared struct {
48+
// callers can call RefShared.Decrement to determine when last caller is done using result, so cleanup if needed can be performed
49+
type RefShared struct {
5050
shared bool
5151
refCount *int64
5252
}
5353

5454
// Decrement will atomically decrement refcounter and will return new value
55-
func (rs *refShared) Decrement() int64 {
55+
func (rs *RefShared) Decrement() int64 {
5656
return atomic.AddInt64(rs.refCount, -1)
5757
}
5858

59-
func (rs *refShared) Shared() bool {
59+
// returns boolean indicator of whether original "ref counter" had more than 1 reference
60+
// it will return same value regardless of whether Decrement() method was called
61+
func (rs *RefShared) Shared() bool {
6062
return rs.shared
6163
}
6264

@@ -65,7 +67,7 @@ func (rs *refShared) Shared() bool {
6567
// time. If a duplicate comes in, the duplicate caller waits for the
6668
// original to complete and receives the same results.
6769
// The return value shared indicates whether v was given to multiple callers (and a reference counter for callers too).
68-
func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared refShared) {
70+
func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared RefShared) {
6971
r := <-g.DoChan(key, fn)
7072
return r.Val, r.Err, r.Shared
7173
}
@@ -104,7 +106,7 @@ func (g *Group) doCall(c *call, key string, fn func() (interface{}, error)) {
104106
delete(g.m, key)
105107
}
106108
//shared := newRefShared(&c.refCount)
107-
shared := refShared{shared: c.refCount > 1, refCount: &c.refCount}
109+
shared := RefShared{shared: c.refCount > 1, refCount: &c.refCount}
108110
for _, ch := range c.chans {
109111
ch <- Result{c.val, c.err, shared}
110112
}

0 commit comments

Comments
 (0)