Skip to content

Commit

Permalink
Replace getClosedSignal() with global closed channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Feb 19, 2022
1 parent c39a8c2 commit 1ae2ab3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions answer.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ type Answer struct {
func ErrorAnswer(m Method, e error) *Answer {
p := &Promise{
method: m,
resolved: newClosedSignal(),
resolved: closedSignal,
err: e,
}
p.ans.f.promise = p
Expand All @@ -392,7 +392,7 @@ func ErrorAnswer(m Method, e error) *Answer {
func ImmediateAnswer(m Method, s Struct) *Answer {
p := &Promise{
method: m,
resolved: newClosedSignal(),
resolved: closedSignal,
result: s.ToPtr(),
}
p.ans.f.promise = p
Expand Down
14 changes: 7 additions & 7 deletions capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"capnproto.org/go/capnp/v3/internal/syncutil"
)

func init() {
close(closedSignal)
}

// An Interface is a reference to a client in a message's capability table.
type Interface struct {
seg *Segment
Expand Down Expand Up @@ -138,7 +142,7 @@ func NewClient(hook ClientHook) *Client {
ClientHook: hook,
done: make(chan struct{}),
refs: 1,
resolved: newClosedSignal(),
resolved: closedSignal,
metadata: *NewMetadata(),
}
h.resolvedHook = h
Expand Down Expand Up @@ -856,7 +860,7 @@ func ErrorClient(e error) *Client {
ClientHook: errorClient{e},
done: make(chan struct{}),
refs: 1,
resolved: newClosedSignal(),
resolved: closedSignal,
metadata: *NewMetadata(),
}
h.resolvedHook = h
Expand All @@ -879,8 +883,4 @@ func (ec errorClient) Brand() Brand {
func (ec errorClient) Shutdown() {
}

func newClosedSignal() chan struct{} {
c := make(chan struct{})
close(c)
return c
}
var closedSignal = make(chan struct{})

0 comments on commit 1ae2ab3

Please sign in to comment.