Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flag to context.Stream indicates if client disconnected in middle of stream #1252

Merged
merged 5 commits into from
Mar 2, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,19 +896,20 @@ func (c *Context) SSEvent(name string, message interface{}) {
})
}

// Stream sends a streaming response.
func (c *Context) Stream(step func(w io.Writer) bool) {
// Stream sends a streaming response and 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
}
}
}
Expand Down