Added stream flag indicates if client disconnected in middle of streaming

This commit is contained in:
Daniel Krom 2018-02-12 21:52:44 +02:00
parent 783c7ee9c1
commit 753188bc98

View File

@ -722,18 +722,19 @@ func (c *Context) SSEvent(name string, message interface{}) {
})
}
func (c *Context) Stream(step func(w io.Writer) bool) {
// Returns a boolean indicates "Is client disconnected in middle of stream"
func (c *Context) Stream(step func(w io.Writer) bool) bool {
w := c.Writer
clientGone := w.CloseNotify()
for {
select {
case <-clientGone:
return
return true
default:
keepOpen := step(w)
w.Flush()
if !keepOpen {
return
return false
}
}
}