From a77f09c82054dce31a95dc23331b0956da59721b Mon Sep 17 00:00:00 2001 From: Steven Allen <steven@stebalien.com> Date: Thu, 27 Jun 2019 20:17:04 +0200 Subject: [PATCH] fix: completely drain on close Issue: We could partially drain and end up with, e.g., a close event missing a matching open event. --- basic.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/basic.go b/basic.go index 2663fc4..c123f2a 100644 --- a/basic.go +++ b/basic.go @@ -104,15 +104,10 @@ func (s *sub) Out() <-chan interface{} { } func (s *sub) Close() error { - stop := make(chan struct{}) go func() { - for { - select { - case <-s.ch: - case <-stop: - close(s.ch) - return - } + // drain the event channel, will return when closed and drained. + // this is necessary to unblock publishes to this channel. + for range s.ch { } }() @@ -135,7 +130,7 @@ func (s *sub) Close() error { s.dropper(n.typ) } } - close(stop) + close(s.ch) return nil }