This commit is contained in:
parent
a4ce0583b7
commit
1b3cabed7e
|
@ -24,9 +24,11 @@ type Event struct {
|
||||||
var EventQueue = make(chan int, MaxQueueLength)
|
var EventQueue = make(chan int, MaxQueueLength)
|
||||||
|
|
||||||
// 用户事件队列.
|
// 用户事件队列.
|
||||||
|
// <sid, chan>
|
||||||
var UserEventQueues = map[string]chan int{}
|
var UserEventQueues = map[string]chan int{}
|
||||||
|
|
||||||
// 用户事件处理器集.
|
// 用户事件处理器集.
|
||||||
|
// <sid, *Handlers>
|
||||||
var UserEventHandlers = map[string]*Handlers{}
|
var UserEventHandlers = map[string]*Handlers{}
|
||||||
|
|
||||||
// 加载事件处理.
|
// 加载事件处理.
|
||||||
|
@ -76,12 +78,15 @@ func InitUserQueue(sid string, handlers ...Handler) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 事件处理接口.
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
Handle(event *Event)
|
Handle(event *Event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 函数指针包装.
|
||||||
type HandleFunc func(event *Event)
|
type HandleFunc func(event *Event)
|
||||||
|
|
||||||
|
// 事件处理默认实现.
|
||||||
func (fn HandleFunc) Handle(event *Event) {
|
func (fn HandleFunc) Handle(event *Event) {
|
||||||
fn(event)
|
fn(event)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue