From cf9182539d166106794166759864c540ac55e3b2 Mon Sep 17 00:00:00 2001 From: RajR Date: Wed, 9 Oct 2019 22:52:12 -0400 Subject: [PATCH] re-implemented WatchRemoteConfigOnChannel() Now WatchRemoteConfigOnChannel() returns '<-chan bool'. This channel signals the change. --- viper.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/viper.go b/viper.go index 5133de7..1fadefe 100644 --- a/viper.go +++ b/viper.go @@ -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.