实现访问日志队列

This commit is contained in:
GoEdgeLab
2021-12-14 12:44:57 +08:00
parent 515ead530d
commit fd120aee09
5 changed files with 278 additions and 66 deletions

View File

@@ -5,7 +5,7 @@ import "sync"
var eventsMap = map[string][]func(){} // event => []callbacks
var locker = sync.Mutex{}
// 增加事件回调
// On 增加事件回调
func On(event string, callback func()) {
locker.Lock()
defer locker.Unlock()
@@ -15,7 +15,7 @@ func On(event string, callback func()) {
eventsMap[event] = callbacks
}
// 通知事件
// Notify 通知事件
func Notify(event string) {
locker.Lock()
callbacks, _ := eventsMap[event]