Skip to content

Commit f7e48e6

Browse files
committed
Minor stylistic cleanup
1 parent 803b677 commit f7e48e6

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

answer.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,19 @@ func (p *Promise) Reject(e error) {
146146
// If e != nil, then this is equivalent to p.Reject(e).
147147
// Otherwise, it is equivalent to p.Fulfill(r).
148148
func (p *Promise) Resolve(r Ptr, e error) {
149-
var (
150-
shutdownPromises []*clientPromise
149+
var shutdownPromises []*clientPromise
151150

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 {
160155
if e != nil {
161156
p.requireUnresolved("Reject")
162157
} else {
163158
p.requireUnresolved("Fulfill")
164159
}
165160
p.caller = nil
166-
clients = p.clients
161+
return p.clients
167162
})
168163

169164
// Pending resolution state: wait for clients to be fulfilled

0 commit comments

Comments
 (0)