优化代码

This commit is contained in:
GoEdgeLab
2022-01-02 22:45:37 +08:00
parent a9af7421d3
commit 716849d070
4 changed files with 65 additions and 3 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]