Refactor changeRestart variable

This commit is contained in:
Max Claus Nunes 2018-06-24 21:05:22 -03:00
parent eb4510b3fe
commit 55cf00b791
1 changed files with 10 additions and 6 deletions

View File

@ -95,7 +95,8 @@ func Run(cfg *Config) error { // nolint: gocyclo
return fmt.Errorf("watcher error: %v", err) return fmt.Errorf("watcher error: %v", err)
} }
var changeRestart bool // flag to know if an exit was caused by a restart from a file changing
changeRestart := false
go watcher.Watch() go watcher.Watch()
for { for {
@ -109,13 +110,16 @@ func Run(cfg *Config) error { // nolint: gocyclo
case err := <-watcher.Errors: case err := <-watcher.Errors:
return fmt.Errorf("error on watching files: %v", err) return fmt.Errorf("error on watching files: %v", err)
case err := <-runner.Errors(): case err := <-runner.Errors():
logger.Debug("Detected program exit: ", err)
// ignore exit by change
if changeRestart { if changeRestart {
changeRestart = false changeRestart = false
} else { continue
logger.Debug("Detected program exit: ", err) }
if err = handleProgramExit(builder, runner, err, cfg.NoRestartOn); err != nil {
return err if err = handleProgramExit(builder, runner, err, cfg.NoRestartOn); err != nil {
} return err
} }
default: default:
time.Sleep(time.Duration(cfg.PollInterval) * time.Millisecond) time.Sleep(time.Duration(cfg.PollInterval) * time.Millisecond)