Skip to content
a Go package to observe notable events in a decoupled fashion
Latest commit 0a148b8 Feb 16, 2013 @mreiferson mreiferson Merge pull request #1 from rafrombrc/master
Add `PostTimeout` function


Package notify enables independent components of an application to observe notable events in a decoupled fashion.

It generalizes the pattern of multiple consumers of an event (ie: the same message delivered to multiple channels) and obviates the need for components to have intimate knowledge of each other (only import notify and the name of the event are shared).


// producer of "my_event"
go func() {
    for {
        time.Sleep(time.Duration(1) * time.Second):
        notify.Post("my_event", time.Now().Unix())

// observer of "my_event" (normally some independent component that
// needs to be notified when "my_event" occurs)
myEventChan := make(chan interface{})
notify.Start("my_event", myEventChan)
go func() {
    for {
        data := <-myEventChan
        log.Printf("MY_EVENT: %#v", data)


func Post(event string, data interface{}) error
    Post a notification (arbitrary data) to the specified event

func PostTimeout(event string, data interface{}, timeout time.Duration) error
    Post a notification to the specified event using the provided timeout for
    any output channels that are blocking

func Start(event string, outputChan chan interface{})
    Start observing the specified event via provided output channel

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
Something went wrong with that request. Please try again.