@@ -41,22 +41,24 @@ type Group struct {
41
41
type Result struct {
42
42
Val interface {}
43
43
Err error
44
- Shared refShared
44
+ Shared RefShared
45
45
}
46
46
47
47
// 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 {
50
50
shared bool
51
51
refCount * int64
52
52
}
53
53
54
54
// Decrement will atomically decrement refcounter and will return new value
55
- func (rs * refShared ) Decrement () int64 {
55
+ func (rs * RefShared ) Decrement () int64 {
56
56
return atomic .AddInt64 (rs .refCount , - 1 )
57
57
}
58
58
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 {
60
62
return rs .shared
61
63
}
62
64
@@ -65,7 +67,7 @@ func (rs *refShared) Shared() bool {
65
67
// time. If a duplicate comes in, the duplicate caller waits for the
66
68
// original to complete and receives the same results.
67
69
// 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 ) {
69
71
r := <- g .DoChan (key , fn )
70
72
return r .Val , r .Err , r .Shared
71
73
}
@@ -104,7 +106,7 @@ func (g *Group) doCall(c *call, key string, fn func() (interface{}, error)) {
104
106
delete (g .m , key )
105
107
}
106
108
//shared := newRefShared(&c.refCount)
107
- shared := refShared {shared : c .refCount > 1 , refCount : & c .refCount }
109
+ shared := RefShared {shared : c .refCount > 1 , refCount : & c .refCount }
108
110
for _ , ch := range c .chans {
109
111
ch <- Result {c .val , c .err , shared }
110
112
}
0 commit comments