Exemplo n.º 1
0
// Starts the PubSub in a goroutine and returns a channel to it
func startPubSub() (ps chan Msg) {
	svc := NewServiceContext()
	psObj := pubsub.NewPubSub(svc)
	ps = make(chan Msg)
	go util.Drain(svc.Game) // For service ready msg
	go psObj.Run(ps)
	return
}
Exemplo n.º 2
0
// Starts the server with a user specificied ServiceContext
func startServerWithCtx(t *testing.T,
	ctx ServiceContext) (svc *CommService, cs chan Msg) {
	// Start new service on port 9190
	svc = NewCommService(ctx, ":9190")
	go util.Drain(ctx.Game) // For service ready msg
	cs = ctx.Comm
	go svc.Run(cs)

	// Start game and pubsub so observers don't lock up
	go game.NewGame(ctx).Run(ctx.Game)
	go pubsub.NewPubSub(ctx).Run(ctx.PubSub)

	// Give time for the service to start listening
	time.Sleep(1e8) // 100 ms
	return svc, cs
}