Skip to content

mattn/go-pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 (mattn.jp@gmail.com)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages