Added explicit Flush method to utils.WriteFlusher
This commit is contained in:
parent
dd9f4524d1
commit
a963ff5d8d
2
api.go
2
api.go
|
@ -236,7 +236,7 @@ func getEvents(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
wf := utils.NewWriteFlusher(w)
|
wf := utils.NewWriteFlusher(w)
|
||||||
wf.Write([]byte{})
|
wf.Flush()
|
||||||
if since != 0 {
|
if since != 0 {
|
||||||
// If since, send previous events that happened after the timestamp
|
// If since, send previous events that happened after the timestamp
|
||||||
for _, event := range srv.events {
|
for _, event := range srv.events {
|
||||||
|
|
|
@ -616,6 +616,13 @@ func (wf *WriteFlusher) Write(b []byte) (n int, err error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush the stream immediately.
|
||||||
|
func (wf *WriteFlusher) Flush() {
|
||||||
|
wf.Lock()
|
||||||
|
defer wf.Unlock()
|
||||||
|
wf.flusher.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
func NewWriteFlusher(w io.Writer) *WriteFlusher {
|
func NewWriteFlusher(w io.Writer) *WriteFlusher {
|
||||||
var flusher http.Flusher
|
var flusher http.Flusher
|
||||||
if f, ok := w.(http.Flusher); ok {
|
if f, ok := w.(http.Flusher); ok {
|
||||||
|
|
Loading…
Reference in New Issue