All Projects → mattn → Go Pubsub

mattn / Go Pubsub

Programming Languages

go
31211 projects - #10 most used programming language

go-pubsub

PubSub model message hub

Usage

To subscribe:

ps := pubsub.New()
ps.Sub(func(i int) {
    fmt.Println("int subscriber: ", i)
})

To publish:

ps.Pub(1)

If the closure captures values, you can use a wrapped function, eg:

// global
var ps = pubsub.New()
// subscribe with a network connection
func Subscribe(conn net.Conn) {
	f := func(i int) { // a closure captures "conn", it will send messages to different network connections
		conn.Write([]byte(fmt.Sprint("int subscriber: ", i)))
	})
	ps.Sub(pubsub.NewWrap(f)) // subscribe with a wrapper
	...
}

Messages are passed to subscriber which have same type argument.

License

MIT: http://mattn.mit-license.org/2013

Author

Yasuhiro Matsumoto ([email protected])

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].