mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 09:34:33 +08:00
Added stream flag indicates if client disconnected in middle of streaming
This commit is contained in:
parent
783c7ee9c1
commit
753188bc98
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user