mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Consistent license message for all the go files * Fixing the last set of unconsistencies with the license headers * Addressing PR review comments * Fixing busy.go and busy_test.go license header
40 lines
1006 B
Go
40 lines
1006 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package config
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
)
|
|
|
|
// emitter enables threadsafe registration and broadcasting to configuration listeners
|
|
type emitter struct {
|
|
listeners sync.Map
|
|
}
|
|
|
|
// AddListener adds a callback function to invoke when the configuration is modified.
|
|
func (e *emitter) AddListener(listener Listener) string {
|
|
id := model.NewId()
|
|
|
|
e.listeners.Store(id, listener)
|
|
|
|
return id
|
|
}
|
|
|
|
// RemoveListener removes a callback function using an id returned from AddListener.
|
|
func (e *emitter) RemoveListener(id string) {
|
|
e.listeners.Delete(id)
|
|
}
|
|
|
|
// invokeConfigListeners synchronously notifies all listeners about the configuration change.
|
|
func (e *emitter) invokeConfigListeners(oldCfg, newCfg *model.Config) {
|
|
e.listeners.Range(func(key, value interface{}) bool {
|
|
listener := value.(Listener)
|
|
listener(oldCfg, newCfg)
|
|
|
|
return true
|
|
})
|
|
}
|