mirror of
https://github.com/spf13/viper
synced 2025-05-10 22:27:18 +00:00
Remove unused eventsWG in WatchConfig
eventsWG.Wait() is called after initWG.Done(), so the inner goroutine is dangling and cannot be waited by the surrounding one. So remove the useless waitGroup
This commit is contained in:
parent
f2cbaea4c2
commit
2e6c46a2ec
1 changed files with 33 additions and 40 deletions
13
viper.go
13
viper.go
|
@ -358,14 +358,13 @@ func (v *Viper) WatchConfig() {
|
|||
configDir, _ := filepath.Split(configFile)
|
||||
realConfigFile, _ := filepath.EvalSymlinks(filename)
|
||||
|
||||
eventsWG := sync.WaitGroup{}
|
||||
eventsWG.Add(1)
|
||||
go func() {
|
||||
watcher.Add(configDir)
|
||||
initWG.Done() // done initializing the watch in this go routine, so the parent routine can move on...
|
||||
|
||||
for {
|
||||
select {
|
||||
case event, ok := <-watcher.Events:
|
||||
if !ok { // 'Events' channel is closed
|
||||
eventsWG.Done()
|
||||
return
|
||||
}
|
||||
currentConfigFile, _ := filepath.EvalSymlinks(filename)
|
||||
|
@ -386,7 +385,6 @@ func (v *Viper) WatchConfig() {
|
|||
}
|
||||
} else if filepath.Clean(event.Name) == configFile &&
|
||||
event.Op&fsnotify.Remove&fsnotify.Remove != 0 {
|
||||
eventsWG.Done()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -394,15 +392,10 @@ func (v *Viper) WatchConfig() {
|
|||
if ok { // 'Errors' channel is not closed
|
||||
log.Printf("watcher error: %v\n", err)
|
||||
}
|
||||
eventsWG.Done()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
watcher.Add(configDir)
|
||||
initWG.Done() // done initializing the watch in this go routine, so the parent routine can move on...
|
||||
eventsWG.Wait() // now, wait for event loop to end in this go-routine...
|
||||
}()
|
||||
initWG.Wait() // make sure that the go routine above fully ended before returning
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue