File tree Expand file tree Collapse file tree 1 file changed +6
-11
lines changed Expand file tree Collapse file tree 1 file changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -146,24 +146,19 @@ func (p *Promise) Reject(e error) {
146
146
// If e != nil, then this is equivalent to p.Reject(e).
147
147
// Otherwise, it is equivalent to p.Fulfill(r).
148
148
func (p * Promise ) Resolve (r Ptr , e error ) {
149
- var (
150
- shutdownPromises []* clientPromise
149
+ var shutdownPromises []* clientPromise
151
150
152
- // We need to access some of these fields from p.state while
153
- // not holding the lock, so we store them here while holding it.
154
- // p.clients cannot be touched in the pending resolution state,
155
- // so we have exclusive access to the variable anyway.
156
- clients map [clientPath ]* clientAndPromise
157
- )
158
-
159
- p .state .With (func (p * promiseState ) {
151
+ // It's ok to extract p.clients and use it while not holding the lock:
152
+ // it may not be accessed in the pending resolution state, so we have
153
+ // exclusive access to the variable anyway.
154
+ clients := mutex .With1 (& p .state , func (p * promiseState ) map [clientPath ]* clientAndPromise {
160
155
if e != nil {
161
156
p .requireUnresolved ("Reject" )
162
157
} else {
163
158
p .requireUnresolved ("Fulfill" )
164
159
}
165
160
p .caller = nil
166
- clients = p .clients
161
+ return p .clients
167
162
})
168
163
169
164
// Pending resolution state: wait for clients to be fulfilled
You can’t perform that action at this time.
0 commit comments