dev #14
@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ Server = (*event)(nil)
|
||||
@ -122,6 +123,10 @@ func (stream *event) GinHandlerFunc(auth func(c *gin.Context) (string, error)) g
|
||||
c.Writer.Header().Set("Connection", "keep-alive")
|
||||
c.Writer.Header().Set("Transfer-Encoding", "chunked")
|
||||
|
||||
time.AfterFunc(time.Second, func() {
|
||||
e <- msgChan{Name: "message", Message: "success"}
|
||||
})
|
||||
|
||||
c.Stream(func(w io.Writer) bool {
|
||||
if msg, ok := <-e; ok {
|
||||
c.SSEvent(msg.Name, msg.Message)
|
||||
@ -129,8 +134,6 @@ func (stream *event) GinHandlerFunc(auth func(c *gin.Context) (string, error)) g
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
e <- msgChan{Name: "message", Message: "success"}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user