Exemplo n.º 1
0
func test_PathId() {
	rout := router.New(router.PathID(), 32, router.BroadcastPolicy)
	chi1 := make(chan string)
	chi2 := make(chan string)
	chi3 := make(chan string)
	cho1 := make(chan string)
	cho2 := make(chan string)
	cho3 := make(chan string)
	done := make(chan bool)
	rout.AttachSendChan(router.PathID("/sport/basketball"), cho1)
	rout.AttachSendChan(router.PathID("/sport/baseball"), cho2)
	rout.AttachSendChan(router.PathID("/sport/basketball/Jordan"), cho3)
	rout.AttachRecvChan(router.PathID("/sport/*"), chi1) //subscribe to all sports news
	rout.AttachRecvChan(router.PathID("/sport/baseball"), chi2)
	rout.AttachRecvChan(router.PathID("/sport/basketball*"), chi3) //subscribe to all basketball news
	go func() {
		cho1 <- "want to play"
		cho1 <- "basketball?"
		close(cho1)
	}()
	go func() {
		cho2 <- "want to watch"
		cho2 <- "baseball?"
		close(cho2)
	}()
	go func() {
		cho3 <- "hello there, anybody know"
		cho3 <- "will Michael Jordan play again?"
		close(cho3)
	}()
	go func() {
		for v := range chi1 {
			fmt.Println("sport fan read: ", v)
		}
		done <- true
	}()
	go func() {
		for v := range chi2 {
			fmt.Println("baseball fan read: ", v)
		}
		done <- true
	}()
	go func() {
		for v := range chi3 {
			fmt.Println("basketball fan read: ", v)
		}
		done <- true
	}()
	<-done
	<-done
	<-done
}
Exemplo n.º 2
0
func Connect(path string, ch interface{}) (*router.RoutedChan, error) {
	return r.AttachSendChan(router.PathID(path), ch)
}
Exemplo n.º 3
0
func PermanentSubscribe(path string, ch interface{}) (*router.RoutedChan, error) {
	return r.AttachRecvChan(router.PathID(path), ch, make(chan *router.BindEvent, 1))
}
Exemplo n.º 4
0
func Subscribe(path string, ch interface{}) (*router.RoutedChan, error) {
	return r.AttachRecvChan(router.PathID(path), ch)
}
Exemplo n.º 5
0
func init() {
	r = router.New(router.PathID(), -1, router.BroadcastPolicy)
}