]> 127.0.0.1 Git - part/.git/commitdiff
improve v0.22.20
authorqydysky <32743305+qydysky@users.noreply.github.com>
Thu, 23 Feb 2023 13:40:59 +0000 (21:40 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Thu, 23 Feb 2023 13:40:59 +0000 (21:40 +0800)
msgq/Msgq.go
msgq/Msgq_test.go

index debdc5dd26d20e9c75fe2a938e1f92dc0c431b47..e864492d09df03494cb9ff86c1bfbc6125792ad3 100644 (file)
@@ -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 {
index 9c90a4612d160dc79559cca42226fc8c522a2d96..4f51eefc3385c9bf73c62bbcb4bdfad817f8d779 100644 (file)
@@ -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 {