@@ -16,8 +16,10 @@ limitations under the License.
16
16
17
17
package promise
18
18
19
- // This file defines interfaces for promsies and futures and related
20
- // things.
19
+ // This file defines interfaces for promises and futures and related
20
+ // things. These are about coordination among multiple goroutines and
21
+ // so are safe for concurrent calls --- although moderated in some
22
+ // cases by a requirement that the caller hold a certain lock.
21
23
22
24
// Readable represents a variable that is initially not set and later
23
25
// becomes set. Some instances may be set to multiple values in
@@ -39,10 +41,16 @@ type Readable interface {
39
41
type LockingReadable interface {
40
42
Readable
41
43
42
- // GetLocked is like Get but the caller must already hold the lock
44
+ // GetLocked is like Get but the caller must already hold the
45
+ // lock. GetLocked may release, and later re-acquire, the lock
46
+ // any number of times. Get may acquire, and later release, the
47
+ // lock any number of times.
43
48
GetLocked () interface {}
44
49
45
- // IsSetLocked is like IsSet but the caller must already hold the lock
50
+ // IsSetLocked is like IsSet but the caller must already hold the
51
+ // lock. IsSetLocked may release, and later re-acquire, the lock
52
+ // any number of times. IsSet may acquire, and later release, the
53
+ // lock any number of times.
46
54
IsSetLocked () bool
47
55
}
48
56
@@ -52,7 +60,8 @@ type WriteOnceOnly interface {
52
60
// Set normally writes a value into this variable, unblocks every
53
61
// goroutine waiting for this variable to have a value, and
54
62
// returns true. In the unhappy case that this variable is
55
- // already set, this method returns false.
63
+ // already set, this method returns false without modifying the
64
+ // variable's value.
56
65
Set (interface {}) bool
57
66
}
58
67
@@ -64,14 +73,23 @@ type WriteOnce interface {
64
73
WriteOnceOnly
65
74
}
66
75
76
+ // LockingWriteOnceOnly is a WriteOnceOnly whose implementation is
77
+ // protected by a lock.
78
+ type LockingWriteOnceOnly interface {
79
+ WriteOnceOnly
80
+
81
+ // SetLocked is like Set but the caller must already hold the
82
+ // lock. SetLocked may release, and later re-acquire, the lock
83
+ // any number of times. Set may acquire, and later release, the
84
+ // lock any number of times
85
+ SetLocked (interface {}) bool
86
+ }
87
+
67
88
// LockingWriteOnce is a WriteOnce whose implementation is protected
68
89
// by a lock.
69
90
type LockingWriteOnce interface {
70
91
LockingReadable
71
- WriteOnceOnly
72
-
73
- // SetLocked is like Set but the caller must already hold the lock
74
- SetLocked (interface {}) bool
92
+ LockingWriteOnceOnly
75
93
}
76
94
77
95
// WriteMultipleOnly represents a variable that is initially not set
@@ -91,12 +109,21 @@ type WriteMultiple interface {
91
109
WriteMultipleOnly
92
110
}
93
111
112
+ // LockingWriteMultipleOnly is a WriteMultipleOnly whose
113
+ // implementation is protected by a lock.
114
+ type LockingWriteMultipleOnly interface {
115
+ WriteMultipleOnly
116
+
117
+ // SetLocked is like Set but the caller must already hold the
118
+ // lock. SetLocked may release, and later re-acquire, the lock
119
+ // any number of times. Set may acquire, and later release, the
120
+ // lock any number of times
121
+ SetLocked (interface {})
122
+ }
123
+
94
124
// LockingWriteMultiple is a WriteMultiple whose implementation is
95
125
// protected by a lock.
96
126
type LockingWriteMultiple interface {
97
127
LockingReadable
98
- WriteMultipleOnly
99
-
100
- // SetLocked is like Set but the caller must already hold the lock
101
- SetLocked (interface {})
128
+ LockingWriteMultipleOnly
102
129
}
0 commit comments