Permalink
Browse files

Added `StopAll` function to close all of the listeners on a given event.

  • Loading branch information...
1 parent 2643b74 commit e3ddb616eea90d4e87dff8513c251ff514678406 @rafrombrc rafrombrc committed Nov 22, 2012
Showing with 20 additions and 0 deletions.
  1. +3 −0 README.md
  2. +17 −0 notify.go
View
@@ -44,5 +44,8 @@ Example:
func Stop(event string, outputChan chan interface{}) error
Stop observing the specified event on the provided output channel
+ func StopAll(event string) error
+ Stop observing the specified event on all channels
+
func Version() string
returns the current version
View
@@ -76,6 +76,23 @@ func Stop(event string, outputChan chan interface{}) error {
return nil
}
+// Stop observing the specified event on all channels
+func StopAll(event string) error {
+ rwMutex.Lock()
+ defer rwMutex.Unlock()
+
+ outChans, ok := events[event]
+ if !ok {
+ return errors.New(E_NOT_FOUND)
+ }
+ for _, ch := range outChans {
+ close(ch)
+ }
+ delete(events, event)
+
+ return nil
+}
+
// Post a notification (arbitrary data) to the specified event
func Post(event string, data interface{}) error {
rwMutex.RLock()

0 comments on commit e3ddb61

Please sign in to comment.