mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2026-05-08 00:49:49 -05:00
fix: sse shutdown context
This commit is contained in:
@@ -17,6 +17,7 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
|
||||
util.Clients[w] = true
|
||||
util.ClientsMutex.Unlock()
|
||||
|
||||
clientDone := make(chan struct{})
|
||||
defer func() {
|
||||
// Unregister the client when the connection is closed
|
||||
util.ClientsMutex.Lock()
|
||||
@@ -24,5 +25,12 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
|
||||
util.ClientsMutex.Unlock()
|
||||
}()
|
||||
|
||||
<-r.Context().Done()
|
||||
select {
|
||||
case <-r.Context().Done():
|
||||
return
|
||||
case <-util.SSEDone:
|
||||
return
|
||||
case <-clientDone:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user