sync support

This commit is contained in:
2020-12-21 17:31:03 +08:00
parent c9cfb6fd8a
commit 79dcaaf249
2 changed files with 45 additions and 34 deletions
+24 -30
View File
@@ -49,6 +49,7 @@ type StarNotifyS struct {
udpPool map[string]*net.UDPAddr
listener net.Listener
isUDP bool
Sync bool
// Stop 停止信 号
Stop chan int
// UDPConn UDP监听
@@ -432,47 +433,40 @@ func (star *StarNotifyS) notify() {
continue
}
}
if mode[0:2] != "sr" {
go func() {
if msg, ok := star.FuncLists[key]; ok {
sdata := msg(rmsg)
replyFunc := func(key string, rmsg SMsg) {
if msg, ok := star.FuncLists[key]; ok {
sdata := msg(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
} else {
if star.defaultFunc != nil {
sdata := star.defaultFunc(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
} else {
if star.defaultFunc != nil {
sdata := star.defaultFunc(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
}
}
}()
}
}
if mode[0:2] != "sr" {
if star.Sync {
go replyFunc(key, rmsg)
} else {
replyFunc(key, rmsg)
}
} else {
if sa, ok := star.lockPool[mode]; ok {
rmsg.wait = sa.wait
star.lockPool[mode] = rmsg
star.lockPool[mode].wait <- 1
} else {
go func() {
if msg, ok := star.FuncLists[key]; ok {
sdata := msg(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
} else {
if star.defaultFunc != nil {
sdata := star.defaultFunc(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
}
}
}()
if star.Sync {
go replyFunc(key, rmsg)
} else {
replyFunc(key, rmsg)
}
}
}
}