Files
zhub/zsub/zgroup.go
lxy ad3f7686ae 修改:主题取消订阅无效 bug
git-svn-id: svn://47.119.165.148/zhub@98 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
2021-02-03 08:01:57 +00:00

40 lines
661 B
Go

package zsub
import (
"sync"
"sync/atomic"
)
type ZGroup struct { // ZGroup
sync.Mutex
conns []*ZConn
offset int32
chMsg chan string // 组消息即时投递
ztopic *ZTopic // 所属topic
}
func (g *ZGroup) appendTo(c *ZConn) {
c.appendTo(g.conns)
go func() { // 每个连接开启一个携程发送数据
for {
select {
case msg, ok := <-g.chMsg:
if !ok {
return
}
err := c.send("message", g.ztopic.topic, msg)
if err != nil { // 失败处理
g.chMsg <- msg
return
}
atomic.AddInt32(&g.offset, 1)
case <-c.stoped:
return
case <-c.substoped[g.ztopic.topic]:
return
}
}
}()
}