Skip to content

Commit

Permalink
Merge pull request docker#93 from rakyll/closed
Browse files Browse the repository at this point in the history
chanotify: do not allow adding new channels if notifier is closed
  • Loading branch information
crosbymichael committed Jan 27, 2016
2 parents 1ade1f6 + 10d291b commit 92233dd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chanotify/chanotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Notifier struct {

m sync.Mutex // guards doneCh
doneCh map[interface{}]chan struct{}
closed bool
}

// New returns a new *Notifier.
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
}

0 comments on commit 92233dd

Please sign in to comment.