Skip to content

Commit

Permalink
Use time.AfterFunc to schedule room termination
Browse files Browse the repository at this point in the history
  • Loading branch information
olzhasar committed Mar 16, 2024
1 parent 0df9ef8 commit 1a1f86f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions backend/pkg/chat/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,13 @@ func (h *Hub) RoomCount() int {

func (h *Hub) scheduleRoomTermination(room *Room) {
go func() {
time.Sleep(EMPTY_ROOM_TIMEOUT)
if room.ClientCount() > 0 || h.rooms[room.ID] == nil {
return
}
delete(h.rooms, room.ID)
metrics.RoomCount.Dec()
time.AfterFunc(EMPTY_ROOM_TIMEOUT, func() {
if room.ClientCount() > 0 || h.rooms[room.ID] == nil {
return
}
delete(h.rooms, room.ID)
metrics.RoomCount.Dec()
})
}()
}

Expand Down

0 comments on commit 1a1f86f

Please sign in to comment.