This commit is contained in:
2020-12-29 14:09:48 +08:00
parent 07e374b83f
commit 164c412c24
2 changed files with 17 additions and 16 deletions
+6 -8
View File
@@ -24,8 +24,6 @@ type StarNotifyC struct {
stopSign context.Context
cancel context.CancelFunc
defaultFunc func(CMsg)
// Stop 停止信 号
Stop chan int
// UseChannel 是否使用channel作为信息传递
UseChannel bool
isUDP bool
@@ -53,11 +51,10 @@ func (star *StarNotifyC) starinitc() {
star.Queue.Encode = true
star.FuncLists = make(map[string]func(CMsg))
star.UseChannel = false
star.Stop = make(chan int, 5)
star.clientSign = make(map[string]chan string)
star.Online = false
star.lockPool = make(map[string]CMsg)
star.Queue.RestoreDuration(time.Second * 2)
star.Queue.RestoreDuration(time.Millisecond * 50)
}
// Notify 用于获取一个通知
@@ -167,6 +164,10 @@ func (star *StarNotifyC) Send(name string) error {
return star.SendValue(name, "")
}
func (star *StarNotifyC) Stoped() <-chan struct{} {
return star.stopSign.Done()
}
func (star *StarNotifyC) SendValueRaw(key string, msg interface{}) error {
encodeData, err := encode(msg)
if err != nil {
@@ -273,7 +274,7 @@ func (star *StarNotifyC) cnotify() {
}
data, err := star.Queue.RestoreOne()
if err != nil {
time.Sleep(time.Microsecond * 2)
time.Sleep(time.Millisecond * 500)
continue
}
if string(data.Msg) == "b612ryzstop" {
@@ -343,9 +344,6 @@ func (star *StarNotifyC) ClientStop() {
star.Send("b612ryzstop")
}
star.cancel()
star.Stop <- 1
star.Stop <- 1
star.Stop <- 1
}
// SetNotify 用于设置关键词的调用函数