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 1 commit
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
Next Next commit
Added stream flag indicates if client disconnected in middle of strea…
…ming
  • Loading branch information
KromDaniel committed Feb 12, 2018
commit 753188bc989bd0665c961201a81a0d91ff87be8a
7 changes: 4 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down