File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
websites/code2/studygolang/src/logic Expand file tree Collapse file tree 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 {
5858 return this .serverMsgQueue [serverId ]
5959}
6060
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+
6167var Book = & book {users : make (map [int ]* UserData )}
6268
6369type book struct {
@@ -73,7 +79,7 @@ func (this *book) AddUser(user, serverId int) *UserData {
7379 this .rwMutex .Lock ()
7480 defer this .rwMutex .Unlock ()
7581 if userData , ok = this .users [user ]; ok {
76- userData .serverMsgQueue [ serverId ] = make ( chan * Message , 1 )
82+ userData .InitMessageQueue ( serverId )
7783 userData .onlineDuartion += time .Now ().Sub (userData .lastAccessTime )
7884 userData .lastAccessTime = time .Now ()
7985 } else {
You can’t perform that action at this time.
0 commit comments