支持注册配置刷新事件
This commit is contained in:
parent
ce71a956e5
commit
fe90f34770
|
@ -11,6 +11,21 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RefreshEvent func()
|
||||||
|
|
||||||
|
var configRefreshEventHandles []func()
|
||||||
|
|
||||||
|
// RegConfigRefreshEvent 当配置刷新时将立即执行被注册的事件处理函数
|
||||||
|
func RegConfigRefreshEvent(handle RefreshEvent) {
|
||||||
|
configRefreshEventHandles = append(configRefreshEventHandles, handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnConfigRefreshEvent() {
|
||||||
|
for _, handle := range configRefreshEventHandles {
|
||||||
|
handle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type LoadHandle func(handle func(filename string, config any) error)
|
type LoadHandle func(handle func(filename string, config any) error)
|
||||||
type RefreshHandle func()
|
type RefreshHandle func()
|
||||||
|
|
||||||
|
@ -74,5 +89,6 @@ func StopTickerLoad() {
|
||||||
func Refresh() {
|
func Refresh() {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
cRefreshHandle()
|
cRefreshHandle()
|
||||||
|
OnConfigRefreshEvent()
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue