From 1ae2ab3f6be49440869790b14b0ba3c5b6e59b32 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Sat, 19 Feb 2022 16:56:23 -0500 Subject: [PATCH] Replace getClosedSignal() with global closed channel. --- answer.go | 4 ++-- capability.go | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/answer.go b/answer.go index 813b9774..f0c360bd 100644 --- a/answer.go +++ b/answer.go @@ -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 @@ -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 diff --git a/capability.go b/capability.go index fd9e1482..135f55a1 100644 --- a/capability.go +++ b/capability.go @@ -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 @@ -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 @@ -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 @@ -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{})