dev #14

Merged
bvbej merged 2 commits from dev into main 2024-09-07 15:55:29 +08:00
Showing only changes of commit ad1e06229f - Show all commits

View File

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time"
) )
var _ Server = (*event)(nil) 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("Connection", "keep-alive")
c.Writer.Header().Set("Transfer-Encoding", "chunked") 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 { c.Stream(func(w io.Writer) bool {
if msg, ok := <-e; ok { if msg, ok := <-e; ok {
c.SSEvent(msg.Name, msg.Message) c.SSEvent(msg.Name, msg.Message)
@ -129,8 +134,6 @@ func (stream *event) GinHandlerFunc(auth func(c *gin.Context) (string, error)) g
} }
return false return false
}) })
e <- msgChan{Name: "message", Message: "success"}
} }
} }