fix map usage in events.go

This commit is contained in:
paladintyrion 2015-06-22 08:36:02 +08:00
parent bb12838d1c
commit 38b64b491a
1 changed files with 7 additions and 10 deletions

View File

@ -92,14 +92,14 @@ func (uq *UserEventQueue) AddHandler(handlers ...Handler) {
// New initializes a user event queue with the specified wide session id. // New initializes a user event queue with the specified wide session id.
func (ueqs queues) New(sid string) *UserEventQueue { func (ueqs queues) New(sid string) *UserEventQueue {
q := ueqs[sid]
if nil != q { if q, ok := ueqs[sid]; ok {
logger.Warnf("Already exist a user queue in session [%s]", sid) logger.Warnf("Already exist a user queue in session [%s]", sid)
return q return q
} }
q = &UserEventQueue{ q := &UserEventQueue{
Sid: sid, Sid: sid,
Queue: make(chan *Event, maxQueueLength), Queue: make(chan *Event, maxQueueLength),
} }
@ -124,14 +124,11 @@ func (ueqs queues) New(sid string) *UserEventQueue {
// Close closes a user event queue with the specified wide session id. // Close closes a user event queue with the specified wide session id.
func (ueqs queues) Close(sid string) { func (ueqs queues) Close(sid string) {
q := ueqs[sid]
if nil == q {
return
}
if q, ok := ueqs[sid]; ok {
close(q.Queue) close(q.Queue)
delete(ueqs, sid) delete(ueqs, sid)
}
} }
// Handler represents an event handler. // Handler represents an event handler.