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:
parent
714961d68f
commit
3dc7dc4fdd
@ -434,7 +434,7 @@ func (c *QQClient) init(tokenLogin bool) error {
|
|||||||
return errors.Wrap(err, "register error")
|
return errors.Wrap(err, "register error")
|
||||||
}
|
}
|
||||||
if tokenLogin {
|
if tokenLogin {
|
||||||
notify := make(chan struct{})
|
notify := make(chan struct{}, 2)
|
||||||
d := c.waitPacket("StatSvc.ReqMSFOffline", func(i any, err error) {
|
d := c.waitPacket("StatSvc.ReqMSFOffline", func(i any, err error) {
|
||||||
notify <- struct{}{}
|
notify <- struct{}{}
|
||||||
})
|
})
|
||||||
|
@ -214,7 +214,7 @@ func (c *QQClient) waitPacket(cmd string, f func(any, error)) func() {
|
|||||||
// waitPacketTimeoutSyncF
|
// waitPacketTimeoutSyncF
|
||||||
// 等待一个数据包解析, 优先级低于 sendAndWait
|
// 等待一个数据包解析, 优先级低于 sendAndWait
|
||||||
func (c *QQClient) waitPacketTimeoutSyncF(cmd string, timeout time.Duration, filter func(any) bool) (r any, e error) {
|
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) {
|
defer c.waitPacket(cmd, func(i any, err error) {
|
||||||
if filter(i) {
|
if filter(i) {
|
||||||
r = i
|
r = i
|
||||||
|
@ -66,7 +66,7 @@ var musicType = [...]musicTypeInfo{
|
|||||||
|
|
||||||
// SendGroupMusicShare 发送群聊音乐卡片
|
// SendGroupMusicShare 发送群聊音乐卡片
|
||||||
func (c *QQClient) SendGroupMusicShare(target int64, msg *message.MusicShareElement) (*message.GroupMessage, error) {
|
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)
|
eid := utils.RandomString(6)
|
||||||
c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) {
|
c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) {
|
||||||
for _, elem := range e.Msg.Elements {
|
for _, elem := range e.Msg.Elements {
|
||||||
|
@ -77,7 +77,7 @@ func (c *QQClient) RefreshStatus() error {
|
|||||||
// SyncSessions 同步会话列表
|
// SyncSessions 同步会话列表
|
||||||
func (c *QQClient) SyncSessions() (*SessionSyncResponse, error) {
|
func (c *QQClient) SyncSessions() (*SessionSyncResponse, error) {
|
||||||
ret := &SessionSyncResponse{}
|
ret := &SessionSyncResponse{}
|
||||||
notifyChan := make(chan bool)
|
notifyChan := make(chan bool, 4)
|
||||||
var groupNum int32 = -1
|
var groupNum int32 = -1
|
||||||
stop := c.waitPacket("RegPrxySvc.PbSyncMsg", func(i any, err error) {
|
stop := c.waitPacket("RegPrxySvc.PbSyncMsg", func(i any, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user