From de1850f18d40ee368fb91adfdf495cc1005da385 Mon Sep 17 00:00:00 2001 From: qydysky Date: Wed, 17 May 2023 23:54:23 +0800 Subject: [PATCH] =?utf8?q?Fix=20=E6=88=BF=E9=97=B4=E5=88=87=E6=8D=A2?= =?utf8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bili_danmu.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/bili_danmu.go b/bili_danmu.go index 6627981..cf7105b 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -88,14 +88,6 @@ func Start() { // 附加功能 savetojson reply.SaveToJson.Init() - var change_room_chan = c.C.Danmu_Main_mq.Pull_tag_chan(`change_room`, 1, context.Background()) - - // 房间初始化 - if c.C.Roomid != 0 { - fmt.Print("房间号: ", strconv.Itoa(c.C.Roomid), "\n") - c.C.Danmu_Main_mq.Push_tag(`change_room`, nil) - } - //使用带tag的消息队列在功能间传递消息 c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{ `change_room`: func(_ any) bool { //房间改变 @@ -137,11 +129,17 @@ func Start() { for exit_sign := true; exit_sign; { if c.C.Roomid == 0 { fmt.Println("回车查看指令") + ctx, cancle := context.WithCancel(context.Background()) select { - case <-change_room_chan: + case <-c.C.Danmu_Main_mq.Pull_tag_chan(`change_room`, 1, ctx): case <-interrupt_chan: exit_sign = false } + cancle() + } else { + // 房间初始化 + fmt.Print("房间号: ", strconv.Itoa(c.C.Roomid), "\n") + c.C.Danmu_Main_mq.Push_tag(`change_room`, nil) } if !exit_sign { -- 2.39.2