1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

client: use buffered channel

this channel use receive with timeout, so we need use buffered to avoid memory leak.
This commit is contained in:
wdvxdr 2022-03-20 13:55:08 +08:00
parent 714961d68f
commit 3dc7dc4fdd
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
4 changed files with 4 additions and 4 deletions

View File

@ -434,7 +434,7 @@ func (c *QQClient) init(tokenLogin bool) error {
return errors.Wrap(err, "register error")
}
if tokenLogin {
notify := make(chan struct{})
notify := make(chan struct{}, 2)
d := c.waitPacket("StatSvc.ReqMSFOffline", func(i any, err error) {
notify <- struct{}{}
})

View File

@ -214,7 +214,7 @@ func (c *QQClient) waitPacket(cmd string, f func(any, error)) func() {
// waitPacketTimeoutSyncF
// 等待一个数据包解析, 优先级低于 sendAndWait
func (c *QQClient) waitPacketTimeoutSyncF(cmd string, timeout time.Duration, filter func(any) bool) (r any, e error) {
notifyChan := make(chan bool)
notifyChan := make(chan bool, 4)
defer c.waitPacket(cmd, func(i any, err error) {
if filter(i) {
r = i

View File

@ -66,7 +66,7 @@ var musicType = [...]musicTypeInfo{
// SendGroupMusicShare 发送群聊音乐卡片
func (c *QQClient) SendGroupMusicShare(target int64, msg *message.MusicShareElement) (*message.GroupMessage, error) {
ch := make(chan *message.GroupMessage)
ch := make(chan *message.GroupMessage, 2)
eid := utils.RandomString(6)
c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) {
for _, elem := range e.Msg.Elements {

View File

@ -77,7 +77,7 @@ func (c *QQClient) RefreshStatus() error {
// SyncSessions 同步会话列表
func (c *QQClient) SyncSessions() (*SessionSyncResponse, error) {
ret := &SessionSyncResponse{}
notifyChan := make(chan bool)
notifyChan := make(chan bool, 4)
var groupNum int32 = -1
stop := c.waitPacket("RegPrxySvc.PbSyncMsg", func(i any, err error) {
if err != nil {