re-implemented WatchRemoteConfigOnChannel()

Now WatchRemoteConfigOnChannel() returns '<-chan bool'. This channel signals the change.
This commit is contained in:
RajR 2019-10-09 22:52:12 -04:00 committed by GitHub
parent 71509d2887
commit cf9182539d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -1639,7 +1639,7 @@ func (v *Viper) WatchRemoteConfig() error {
return v.watchKeyValueConfig()
}
func (v *Viper) WatchRemoteConfigOnChannel() error {
func (v *Viper) WatchRemoteConfigOnChannel() (<-chan bool, error) {
return v.watchKeyValueConfigOnChannel()
}
@ -1670,20 +1670,23 @@ func (v *Viper) getRemoteConfig(provider RemoteProvider) (map[string]interface{}
}
// Retrieve the first found remote configuration.
func (v *Viper) watchKeyValueConfigOnChannel() error {
func (v *Viper) watchKeyValueConfigOnChannel() (<-chan bool, error) {
wCh := make(chan bool)
for _, rp := range v.remoteProviders {
respc, _ := RemoteConfig.WatchChannel(rp)
//Todo: Add quit channel
go func(rc <-chan *RemoteResponse) {
go func(rc <-chan *RemoteResponse, rc2 chan<- bool) {
for {
b := <-rc
reader := bytes.NewReader(b.Value)
v.unmarshalReader(reader, v.kvstore)
rc2 <- true
}
}(respc)
return nil
}(respc, wCh)
return wCh, nil
}
return RemoteConfigError("No Files Found")
close(wCh)
return nil, RemoteConfigError("No Files Found")
}
// Retrieve the first found remote configuration.