@@ -11,9 +11,7 @@ import (
1111 "time"
1212)
1313
14- var reloadPage = make (chan struct {})
15-
16- var countRequests atomic.Int32
14+ var reloadPageBool atomic.Bool
1715
1816type liveReload struct {
1917 errorLogger * log.Logger
@@ -50,7 +48,7 @@ func (cmd *Cmd) StartLiveReload(siteDataPath string) {
5048 for _ , rootDir := range lr .rootDirs {
5149 if lr .traverseDirectory (rootDir ) {
5250 cmd .VanillaRender (lr .siteDataPath )
53- reloadPage <- struct {}{}
51+ reloadPageBool . CompareAndSwap ( false , true )
5452 }
5553 }
5654 if ! lr .serverRunning {
@@ -115,8 +113,6 @@ func (lr *liveReload) startServer(addr string) {
115113}
116114
117115func eventsHandler (w http.ResponseWriter , r * http.Request ) {
118- countRequests .Add (1 )
119-
120116 // Set CORS headers to allow all origins.
121117 w .Header ().Set ("Access-Control-Allow-Origin" , "*" )
122118 w .Header ().Set ("Access-Control-Expose-Headers" , "Content-Type" )
@@ -125,10 +121,7 @@ func eventsHandler(w http.ResponseWriter, r *http.Request) {
125121 w .Header ().Set ("Cache-Control" , "no-cache" )
126122 w .Header ().Set ("Connection" , "keep-alive" )
127123
128- if countRequests .Load () == 1 {
129- <- reloadPage
130- } else {
131- countRequests .Store (countRequests .Load () - 1 )
124+ if ! reloadPageBool .Load () {
132125 return
133126 }
134127
@@ -139,5 +132,5 @@ func eventsHandler(w http.ResponseWriter, r *http.Request) {
139132 }
140133 w .(http.Flusher ).Flush ()
141134
142- countRequests . Store ( countRequests . Load () - 1 )
135+ reloadPageBool . CompareAndSwap ( true , false )
143136}
0 commit comments