-
Notifications
You must be signed in to change notification settings - Fork 3
/
sse.go
42 lines (36 loc) · 1.05 KB
/
sse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package sseKit
import (
"github.com/richelieu-yang/chimera/v3/src/component/web/push/pushKit"
"github.com/richelieu-yang/chimera/v3/src/core/interfaceKit"
"time"
)
// NewProcessor
/*
!!!: 需要先调用 pushKit.MustSetUp 或 pushKit.SetUp.
@param idGenerator 可以为nil(将使用xid)
@param listener 不能为nil
@param msgType 消息类型
@param pongInterval pong的周期(<=0则不发送pong)
*/
func NewProcessor(idGenerator func() (string, error), listener pushKit.Listener, msgType *messageType, pongInterval time.Duration) (pushKit.Processor, error) {
if err := interfaceKit.AssertNotNil(msgType, "msgType"); err != nil {
return nil, err
}
if err := pushKit.CheckSetup(); err != nil {
return nil, err
}
if idGenerator == nil {
idGenerator = pushKit.DefaultIdGenerator()
}
listeners, err := pushKit.NewListeners(listener, true)
if err != nil {
return nil, err
}
processor := &sseProcessor{
idGenerator: idGenerator,
listeners: listeners,
msgType: msgType,
pongInterval: pongInterval,
}
return processor, nil
}