From 893c6cae07ef564cbdd2796589c449dd2ac87d21 Mon Sep 17 00:00:00 2001 From: Daniel Krom Date: Sat, 2 Mar 2019 17:07:37 +0200 Subject: [PATCH] Added stream flag indicates if client disconnected in middle of streaming (#1252) --- context.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index e9735d28..5dc7f8a0 100644 --- a/context.go +++ b/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 } } }