Пример #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
}
Пример #2
0
func main() {
	svc := NewServiceContext()

	comm.AvatarFunc = sf.MakeAvatar
	go comm.NewCommService(svc, "0.0.0.0:9190").Run(svc.Comm)
	go pubsub.NewPubSub(svc).Run(svc.PubSub)
	go sf.NewWorld(svc).Run(svc.World)

	game.InitFunc = initGameSvc
	game := game.NewGame(svc)

	game.Run(svc.Game)
}
Пример #3
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
}