Skip to content

a Go package to observe notable events in a decoupled fashion

Notifications You must be signed in to change notification settings

bitly/go-notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

go-notify

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).

Example:

// 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)
    }
}()

Functions

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

About

a Go package to observe notable events in a decoupled fashion

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages