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) {
|
func (s *Server) joinAndServe(p person) {
|
||||||
slog.Debug("joining", "player", p.id)
|
slog.Debug("joining", "player", p.id)
|
||||||
ctx, stop := context.WithTimeoutCause(context.Background(), 10*time.Minute, errQueueEmpty)
|
ctx, stop := context.WithTimeoutCause(context.Background(), 10*time.Minute, errQueueEmpty)
|
||||||
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
|
defer close(ch)
|
||||||
for {
|
for {
|
||||||
_, _, err := p.conn.Read(context.Background())
|
_, _, err := p.conn.Read(context.Background())
|
||||||
if err != nil || ctx.Err() != nil {
|
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)
|
id, chall, deal := s.l.Queue(ctx, p.id)
|
||||||
stop()
|
stop()
|
||||||
|
<-ch
|
||||||
if id == (lobby.GameID{}) {
|
if id == (lobby.GameID{}) {
|
||||||
// Context canceled.
|
// Context canceled.
|
||||||
p.conn.Close(websocket.StatusTryAgainLater, "sorry, queue is empty...")
|
p.conn.Close(websocket.StatusTryAgainLater, "sorry, queue is empty...")
|
||||||
|
Loading…
Reference in New Issue
Block a user