From 10d291b825d4d198335cbcbde4ba1202c2cf485d Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Wed, 27 Jan 2016 13:59:45 -0800 Subject: [PATCH] chanotify: do not allow adding new channels if notifier is closed Signed-off-by: Burcu Dogan --- chanotify/chanotify.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chanotify/chanotify.go b/chanotify/chanotify.go index 932bfc1..a317fa9 100644 --- a/chanotify/chanotify.go +++ b/chanotify/chanotify.go @@ -15,6 +15,7 @@ type Notifier struct { m sync.Mutex // guards doneCh doneCh map[interface{}]chan struct{} + closed bool } // New returns a new *Notifier. @@ -42,6 +43,9 @@ func (n *Notifier) killWorker(id interface{}, done chan struct{}) { func (n *Notifier) Add(id interface{}, ch <-chan struct{}) { done := make(chan struct{}) n.m.Lock() + if n.closed { + panic("notifier closed; cannot add the channel") + } n.doneCh[id] = done n.m.Unlock() @@ -73,5 +77,5 @@ func (n *Notifier) Close() { close(done) } close(n.c) - // TODO(jbd): Don't allow Add after Close returns. + n.closed = true }