Compare commits
2 Commits
3c70ad2377
...
d3513ae4fa
Author | SHA1 | Date | |
---|---|---|---|
d3513ae4fa | |||
99264c6715 |
@ -1,12 +1,15 @@
|
|||||||
package sse
|
package sse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"gitea.bvbej.com/bvbej/base-golang/pkg/mux"
|
"gitea.bvbej.com/bvbej/base-golang/pkg/mux"
|
||||||
|
"gitea.bvbej.com/bvbej/base-golang/pkg/ticker"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Server = (*event)(nil)
|
var _ Server = (*event)(nil)
|
||||||
@ -31,9 +34,9 @@ type msgChan struct {
|
|||||||
type event struct {
|
type event struct {
|
||||||
SessionList sync.Map
|
SessionList sync.Map
|
||||||
Count atomic.Int32
|
Count atomic.Int32
|
||||||
|
|
||||||
Register chan clientChan
|
Register chan clientChan
|
||||||
Unregister chan any
|
Unregister chan any
|
||||||
|
Ticker ticker.Ticker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() Server {
|
func NewServer() Server {
|
||||||
@ -42,8 +45,12 @@ func NewServer() Server {
|
|||||||
Count: atomic.Int32{},
|
Count: atomic.Int32{},
|
||||||
Register: make(chan clientChan),
|
Register: make(chan clientChan),
|
||||||
Unregister: make(chan any),
|
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()
|
go e.listen()
|
||||||
|
|
||||||
return e
|
return e
|
||||||
|
Loading…
Reference in New Issue
Block a user