Rename the receiver name

Signed-off-by: Burcu Dogan <jbd@google.com>
This commit is contained in:
Burcu Dogan 2016-01-21 12:59:42 -08:00
parent 9778225c58
commit 85bc51df33

View file

@ -28,22 +28,22 @@ func New() *Notifier {
// Chan returns channel on which client listen for notifications. // Chan returns channel on which client listen for notifications.
// IDs of notifications is sent to the returned channel. // IDs of notifications is sent to the returned channel.
func (s *Notifier) Chan() <-chan string { func (n *Notifier) Chan() <-chan string {
return s.c return n.c
} }
func (s *Notifier) killWorker(id string, done chan struct{}) { func (n *Notifier) killWorker(id string, done chan struct{}) {
s.m.Lock() n.m.Lock()
delete(s.doneCh, id) delete(n.doneCh, id)
s.m.Unlock() n.m.Unlock()
} }
// Add adds new notification channel to Notifier. // Add adds new notification channel to Notifier.
func (s *Notifier) Add(ch <-chan struct{}, id string) { func (n *Notifier) Add(ch <-chan struct{}, id string) {
done := make(chan struct{}) done := make(chan struct{})
s.m.Lock() n.m.Lock()
s.doneCh[id] = done n.doneCh[id] = done
s.m.Unlock() n.m.Unlock()
go func(ch <-chan struct{}, id string, done chan struct{}) { go func(ch <-chan struct{}, id string, done chan struct{}) {
for { for {
@ -52,13 +52,13 @@ func (s *Notifier) Add(ch <-chan struct{}, id string) {
if !ok { if !ok {
// If the channel is closed, we don't need the goroutine // If the channel is closed, we don't need the goroutine
// or the done channel mechanism running anymore. // or the done channel mechanism running anymore.
s.killWorker(id, done) n.killWorker(id, done)
return return
} }
s.c <- id n.c <- id
case <-done: case <-done:
// We don't need this goroutine running anymore, return. // We don't need this goroutine running anymore, return.
s.killWorker(id, done) n.killWorker(id, done)
return return
} }
} }
@ -66,12 +66,12 @@ func (s *Notifier) Add(ch <-chan struct{}, id string) {
} }
// Close closes the notifier and releases its underlying resources. // Close closes the notifier and releases its underlying resources.
func (s *Notifier) Close() { func (n *Notifier) Close() {
s.m.Lock() n.m.Lock()
defer s.m.Unlock() defer n.m.Unlock()
for _, done := range s.doneCh { for _, done := range n.doneCh {
close(done) close(done)
} }
close(s.c) close(n.c)
// TODO(jbd): Don't allow Add after Close returns. // TODO(jbd): Don't allow Add after Close returns.
} }