[🚀] message
This commit is contained in:
parent
99264c6715
commit
e99a8dbcd6
@ -1,15 +1,12 @@
|
||||
package sse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.bvbej.com/bvbej/base-golang/pkg/mux"
|
||||
"gitea.bvbej.com/bvbej/base-golang/pkg/ticker"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ Server = (*event)(nil)
|
||||
@ -36,7 +33,6 @@ type event struct {
|
||||
Count atomic.Int32
|
||||
Register chan clientChan
|
||||
Unregister chan any
|
||||
Ticker ticker.Ticker
|
||||
}
|
||||
|
||||
func NewServer() Server {
|
||||
@ -45,12 +41,8 @@ func NewServer() Server {
|
||||
Count: atomic.Int32{},
|
||||
Register: make(chan clientChan),
|
||||
Unregister: make(chan any),
|
||||
Ticker: ticker.New(time.Second * 3),
|
||||
}
|
||||
|
||||
go e.Ticker.Process(func() {
|
||||
e.Broadcast("ping", fmt.Sprintf("%d", time.Now().Unix()))
|
||||
})
|
||||
go e.listen()
|
||||
|
||||
return e
|
||||
@ -137,6 +129,8 @@ 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