func (g *Game) runSync(ctx context.Context, wg *sync.WaitGroup, in <-chan message.Message, out chan<- message.Message, idleTicker *time.Ticker) {
	defer wg.Done()
	active := false
	send := g.sendMessage(out)
	messageHandlers := map[message.Type]messageHandler{
		message.JoinGame:         g.handleGameJoin,
		message.DeleteGame:       g.handleGameDelete,
		message.ChangeGameStatus: g.handleGameStatusChange,
		message.SnagGameTile:     g.handleGameSnag,
		message.SwapGameTile:     g.handleGameSwap,
		message.MoveGameTile:     g.handleGameTilesMoved,
		message.GameChat:         g.handleGameChat,
		message.RefreshGameBoard: g.handleBoardRefresh,
	}
	for { // BLOCKING
		select {
		case <-ctx.Done():
			return
		case m, ok := <-in:
			if !ok {
				return
			}
			g.handleMessage(ctx, m, send, &active, messageHandlers)
			if m.Type == message.DeleteGame {
				return
			}
		case <-idleTicker.C:
			var m message.Message
			if !active {
				g.log.Printf("deleted game %v due to inactivity", g.id)
				g.handleGameDelete(ctx, m, send)
				return
			}
			active = false
		}
	}
}
// runSync runs the game until the context is closed or the input channel closes.
runSync runs the game until the context is closed or the input channel closes.
// runSync runs the game until the context is closed or the input channel closes .
func (g *Game) runSync(ctx context.Context, wg *sync.WaitGroup, in <-chan message.Message, out chan<- message.Message, idleTicker *time.Ticker) {
	defer wg.Done()
	active := false
	send := g.sendMessage(out)
	messageHandlers := map[message.Type]messageHandler{
		message.JoinGame:         g.handleGameJoin,
		message.DeleteGame:       g.handleGameDelete,
		message.ChangeGameStatus: g.handleGameStatusChange,
		message.SnagGameTile:     g.handleGameSnag,
		message.SwapGameTile:     g.handleGameSwap,
		message.MoveGameTile:     g.handleGameTilesMoved,
		message.GameChat:         g.handleGameChat,
		message.RefreshGameBoard: g.handleBoardRefresh,
	}
	for { 
		select {
		case <-ctx.Done():
			return
		case m, ok := <-in:
			if !ok {
				return
			}
			g.handleMessage(ctx, m, send, &active, messageHandlers)
			if m.Type == message.DeleteGame {
				return
			}
		case <-idleTicker.C:
			var m message.Message
			if !active {
				g.log.Printf("deleted game %v due to inactivity", g.id)
				g.handleGameDelete(ctx, m, send)
				return
			}
			active = false
		}
	}
}
func ( g * Game ) runSync ( ctx context . Context , wg * sync . WaitGroup , in <- chan message . Message , out chan <- message . Message , idleTicker * time . Ticker ) { defer wg . Done ( ) active := false send := g . sendMessage ( out ) messageHandlers := map [ message . Type ] messageHandler { message . JoinGame : g . handleGameJoin , message . DeleteGame : g . handleGameDelete , message . ChangeGameStatus : g . handleGameStatusChange , message . SnagGameTile : g . handleGameSnag , message . SwapGameTile : g . handleGameSwap , message . MoveGameTile : g . handleGameTilesMoved , message . GameChat : g . handleGameChat , message . RefreshGameBoard : g . handleBoardRefresh , } for { select { case <- ctx . Done ( ) : return case m , ok := <- in : if ! ok { return } g . handleMessage ( ctx , m , send , & active , messageHandlers ) if m . Type == message . DeleteGame { return } case <- idleTicker . C : var m message . Message if ! active { g . log . Printf ( " " , g . id ) g . handleGameDelete ( ctx , m , send ) return } active = false } } }
runSync runs the game until the context is closed or the input channel closes.
runSync runs the game until the context is closed or the input channel closes .
// BLOCKING