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 w := c.Writer
clientGone := w.CloseNotify() clientGone := w.CloseNotify()
for { for {
select { select {
case <-clientGone: case <-clientGone:
return return true
default: default:
keepOpen := step(w) keepOpen := step(w)
w.Flush() w.Flush()
if !keepOpen { if !keepOpen {
return return false
} }
} }
} }