sync with heartbeat reader
This commit is contained in:
parent
30897827e4
commit
e27e0f571d
@ -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...")
|
||||
|
Loading…
Reference in New Issue
Block a user