Skip to content

Commit 2ad05d6

Browse files
authored
Merge pull request capnproto#515 from zenhack/rc-pkg
Use the rc package for refcounting inside the implementation of Client.
2 parents 3c7e74f + ad58550 commit 2ad05d6

File tree

8 files changed

+230
-250
lines changed

8 files changed

+230
-250
lines changed

answer.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"capnproto.org/go/capnp/v3/exc"
99
"capnproto.org/go/capnp/v3/internal/str"
10+
"zenhack.net/go/util/deferred"
1011
"zenhack.net/go/util/sync/mutex"
1112
)
1213

@@ -135,7 +136,8 @@ func (p *Promise) Reject(e error) {
135136
// If e != nil, then this is equivalent to p.Reject(e).
136137
// Otherwise, it is equivalent to p.Fulfill(r).
137138
func (p *Promise) Resolve(r Ptr, e error) {
138-
var shutdownPromises []*clientPromise
139+
dq := &deferred.Queue{}
140+
defer dq.Run()
139141

140142
// It's ok to extract p.clients and use it while not holding the lock:
141143
// it may not be accessed in the pending resolution state, so we have
@@ -155,8 +157,7 @@ func (p *Promise) Resolve(r Ptr, e error) {
155157
res := resolution{p.method, r, e}
156158
for path, cp := range clients {
157159
t := path.transform()
158-
cp.promise.fulfill(res.client(t))
159-
shutdownPromises = append(shutdownPromises, cp.promise)
160+
cp.promise.fulfill(dq, res.client(t))
160161
cp.promise = nil
161162
}
162163

@@ -168,9 +169,6 @@ func (p *Promise) Resolve(r Ptr, e error) {
168169
}
169170
p.signals = nil
170171
})
171-
for _, promise := range shutdownPromises {
172-
promise.shutdown()
173-
}
174172
}
175173

176174
// requireUnresolved is a helper method for checking for duplicate

0 commit comments

Comments
 (0)