示例#1
0
文件: server.go 项目: luke/subhub
func New(opts *Options) *server {
	s := &server{
		opts: opts,
		// sockets: make(map[string]*socket),
		pubsub: pubsub.New(&opts.PubSub),
	}
	return s
}
示例#2
0
文件: main.go 项目: luke/subhub
func main() {

	log.Println("testing pubsub")

	var ps pubsub.PubSub
	ps = pubsub.New(pubsub.DefaultOptions)
	ps.Start()

	sub := &Sub{}
	ps.Subscribe(sub, "baz")

	msg := &pubsub.Message{
		Name:   "foo",
		Data:   "bar",
		Sender: "me",
	}
	num, err := ps.Publish("baz", msg)
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("send ", num)
	}

	msg2 := &pubsub.Message{
		Name:   "foo2",
		Data:   "bar2",
		Sender: "testsub",
	}
	num, err = ps.Publish("baz", msg2)
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("send ", num)
	}

	foo := make(chan bool)
	<-foo

}