From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Thu, 23 Feb 2023 13:40:59 +0000 (+0800) Subject: improve X-Git-Tag: v0.22.20 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=052ffeecbcfc549bca782459c203fe9bfd078060;p=part%2F.git improve --- diff --git a/msgq/Msgq.go b/msgq/Msgq.go index debdc5d..e864492 100644 --- a/msgq/Msgq.go +++ b/msgq/Msgq.go @@ -83,10 +83,13 @@ type MsgType[T any] struct { m *Msgq } -func (m *MsgType[T]) Push_tag(Tag string, Data T) { - if m.m == nil { - m.m = New() +func NewType[T any]() *MsgType[T] { + return &MsgType[T]{ + m: New(), } +} + +func (m *MsgType[T]) Push_tag(Tag string, Data T) { m.m.Push(Msgq_tag_data{ Tag: Tag, Data: Data, @@ -94,9 +97,6 @@ func (m *MsgType[T]) Push_tag(Tag string, Data T) { } func (m *MsgType[T]) Pull_tag(func_map map[string]func(T) (disable bool)) { - if m.m == nil { - m.m = New() - } m.m.Register(func(data any) (disable bool) { if d, ok := data.(Msgq_tag_data); ok { if f, ok := func_map[d.Tag]; ok { diff --git a/msgq/Msgq_test.go b/msgq/Msgq_test.go index 9c90a46..4f51eef 100644 --- a/msgq/Msgq_test.go +++ b/msgq/Msgq_test.go @@ -334,7 +334,7 @@ func Test_msgq5(t *testing.T) { } func Test_msgq6(t *testing.T) { - msg := MsgType[int]{} + msg := NewType[int]() msg.Pull_tag(map[string]func(int) (disable bool){ `1`: func(b int) (disable bool) { if b != 0 {