Browse Source

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

Daniel Krom 6 năm trước cách đây
mục cha
commit
893c6cae07
1 tập tin đã thay đổi với 5 bổ sung4 xóa
  1. 5 4
      context.go

+ 5 - 4
context.go

@@ -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
 			}
 		}
 	}