diff --git a/routes/room_page.go b/routes/room_page.go
index 513029f..b5f3cb8 100644
--- a/routes/room_page.go
+++ b/routes/room_page.go
@@ -37,14 +37,20 @@ func streamingBsRoute() http.HandlerFunc {
w.Header().Set("Content-Type", "text/event-stream")
startTime, endTime := 0, 0
for {
- log.Printf("another step in streaming bs")
- data := "data:
hello with data %d! waited %d
\n\n"
- startTime = time.Now().Nanosecond()
- diff := endTime - startTime
- fmt.Fprintf(w, data, rand.Intn(100), diff)
- w.(http.Flusher).Flush()
- time.Sleep(10 * time.Second)
- endTime = time.Now().Nanosecond()
+ select {
+ case <-r.Context().Done():
+ log.Printf("canlecced streaming!")
+ return
+ default:
+ log.Printf("another step in streaming bs")
+ data := "data: hello with data %d! waited %d
\n\n"
+ startTime = time.Now().Nanosecond()
+ diff := endTime - startTime
+ fmt.Fprintf(w, data, rand.Intn(100), diff)
+ w.(http.Flusher).Flush()
+ time.Sleep(3 * time.Second)
+ endTime = time.Now().Nanosecond()
+ }
}
}
}