Skip to content

Commit

Permalink
sync gin #382
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou committed Mar 1, 2019
1 parent 871ad40 commit 1ba5ef4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions realtime-chat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ func stream(c *gin.Context) {
listener := openListener(roomid)
defer closeListener(roomid, listener)

clientGone := c.Writer.CloseNotify()
c.Stream(func(w io.Writer) bool {
c.SSEvent("message", <-listener)
return true
select {
case <-clientGone:
return false
case message := <-listener:
c.SSEvent("message", message)
return true
}
})
}

Expand Down

0 comments on commit 1ba5ef4

Please sign in to comment.