Merge pull request #232 from PaladinTyrion/master

fix map usage in events.go
This commit is contained in:
Liang Ding 2015-06-22 09:11:22 +08:00
commit 8ecd8eb2fc
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.
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)
return q
}
q = &UserEventQueue{
q := &UserEventQueue{
Sid: sid,
Queue: make(chan *Event, maxQueueLength),
}
@ -124,15 +124,12 @@ func (ueqs queues) New(sid string) *UserEventQueue {
// Close closes a user event queue with the specified wide session id.
func (ueqs queues) Close(sid string) {
q := ueqs[sid]
if nil == q {
return
}
if q, ok := ueqs[sid]; ok {
close(q.Queue)
delete(ueqs, sid)
}
}
// Handler represents an event handler.
type Handler interface {