File tree 1 file changed +7
-1
lines changed
websites/code2/studygolang/src/logic
1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,12 @@ func (this *UserData) MessageQueue(serverId int) chan *Message {
58
58
return this .serverMsgQueue [serverId ]
59
59
}
60
60
61
+ func (this * UserData ) InitMessageQueue (serverId int ) {
62
+ this .rwMutex .Lock ()
63
+ defer this .rwMutex .Unlock ()
64
+ this .serverMsgQueue [serverId ] = make (chan * Message , 1 )
65
+ }
66
+
61
67
var Book = & book {users : make (map [int ]* UserData )}
62
68
63
69
type book struct {
@@ -73,7 +79,7 @@ func (this *book) AddUser(user, serverId int) *UserData {
73
79
this .rwMutex .Lock ()
74
80
defer this .rwMutex .Unlock ()
75
81
if userData , ok = this .users [user ]; ok {
76
- userData .serverMsgQueue [ serverId ] = make ( chan * Message , 1 )
82
+ userData .InitMessageQueue ( serverId )
77
83
userData .onlineDuartion += time .Now ().Sub (userData .lastAccessTime )
78
84
userData .lastAccessTime = time .Now ()
79
85
} else {
You can’t perform that action at this time.
0 commit comments