Giter Site home page Giter Site logo

go-notify's Introduction

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

go-notify's People

Contributors

mreiferson avatar rafrombrc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.