Skip to content
Myr

Added stream flag indicates if client disconnected in middle of streaming (#1252)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Krom · committed by 田欧 · parent 3b84a43 · Browse files · 1 file+5 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−4 removed

  • other:+5 added−4 removed

1 file+5 added−4 removed

modified:context.go+5 added-4 removed
894 unmodified lines
895 Data: message,896 })897}898899// Stream sends a streaming response.900func (c *Context) Stream(step func(w io.Writer) bool) {899// Stream sends a streaming response and returns a boolean900// indicates "Is client disconnected in middle of stream"901func (c *Context) Stream(step func(w io.Writer) bool) bool {902 w := c.Writer903 clientGone := w.CloseNotify()904 for {905 select {906 case <-clientGone:906 return907 return true908 default:909 keepOpen := step(w)910 w.Flush()911 if !keepOpen {911 return912 return false913 }914 }915 }916}
112 unmodified lines