File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed
Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ func main() {
3737 ws .HandleFunc ("/debug/statsviz/ws" , srv .Ws ())
3838
3939 // Server start
40- go http .Serve (m .Match (cmux .HTTP1HeaderField ("Upgrade " , "websocket " )), ws )
40+ go http .Serve (m .Match (cmux .HTTP1HeaderField ("Accept " , "text/event-stream " )), ws )
4141 go fasthttp .Serve (m .Match (cmux .Any ()), r .Handler )
4242 fmt .Println ("Point your browser to http://localhost:8083/debug/statsviz/" )
4343 m .Serve ()
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ func main() {
4343 fmt .Println ("Point your browser to http://localhost:8093/debug/statsviz/" )
4444
4545 // Server start
46- go http .Serve (m .Match (cmux .HTTP1HeaderField ("Upgrade " , "websocket " )), ws )
46+ go http .Serve (m .Match (cmux .HTTP1HeaderField ("Accept " , "text/event-stream " )), ws )
4747 go app .Listener (m .Match (cmux .Any ()))
4848 m .Serve ()
4949}
Original file line number Diff line number Diff line change @@ -296,12 +296,33 @@ func (s *Server) startTransfer(w io.Writer) {
296296 <- c
297297}
298298func (s * Server ) callData () {
299+ {
300+ //the first time it was sent immediately
301+ buffer := bytes.Buffer {}
302+ buffer .WriteString ("data: " )
303+ if err := s .plots .WriteValues (& buffer ); err == nil {
304+ buffer .WriteString ("\n \n " )
305+ err = s .onData [0 ](buffer .Bytes ())
306+ if err != nil {
307+ s .lock .Lock ()
308+ if len (s .onData ) == 1 {
309+ s .onData = nil
310+ s .lock .Unlock ()
311+ return
312+ } else {
313+ s .onData = s .onData [1 :]
314+ }
315+ s .lock .Unlock ()
316+ }
317+ }
318+ }
299319 tick := time .NewTicker (s .intv )
300320 defer tick .Stop ()
301321 for range tick .C {
302322 buffer := bytes.Buffer {}
303323 buffer .WriteString ("data: " )
304324 if err := s .plots .WriteValues (& buffer ); err != nil {
325+ //maybe all connections should be closed?
305326 //fmt.Println("Error plots.WriteValues:", err)
306327 continue
307328 }
You can’t perform that action at this time.
0 commit comments