sync with heartbeat reader

This commit is contained in:
Branden J Brown 2024-02-02 21:18:03 -06:00
parent 30897827e4
commit e27e0f571d
1 changed files with 3 additions and 0 deletions

View File

@ -197,7 +197,9 @@ func (s *Server) Queue(w http.ResponseWriter, r *http.Request) {
func (s *Server) joinAndServe(p person) {
slog.Debug("joining", "player", p.id)
ctx, stop := context.WithTimeoutCause(context.Background(), 10*time.Minute, errQueueEmpty)
ch := make(chan struct{})
go func() {
defer close(ch)
for {
_, _, err := p.conn.Read(context.Background())
if err != nil || ctx.Err() != nil {
@ -207,6 +209,7 @@ func (s *Server) joinAndServe(p person) {
}()
id, chall, deal := s.l.Queue(ctx, p.id)
stop()
<-ch
if id == (lobby.GameID{}) {
// Context canceled.
p.conn.Close(websocket.StatusTryAgainLater, "sorry, queue is empty...")