From 55cf00b7919d78e8a87e5875e0d39400323cb3f9 Mon Sep 17 00:00:00 2001 From: Max Claus Nunes Date: Sun, 24 Jun 2018 21:05:22 -0300 Subject: [PATCH] Refactor changeRestart variable --- gaper.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gaper.go b/gaper.go index 42451e8..2334461 100644 --- a/gaper.go +++ b/gaper.go @@ -95,7 +95,8 @@ func Run(cfg *Config) error { // nolint: gocyclo 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() for { @@ -109,13 +110,16 @@ func Run(cfg *Config) error { // nolint: gocyclo case err := <-watcher.Errors: return fmt.Errorf("error on watching files: %v", err) case err := <-runner.Errors(): + logger.Debug("Detected program exit: ", err) + + // ignore exit by change if changeRestart { changeRestart = false - } else { - logger.Debug("Detected program exit: ", err) - if err = handleProgramExit(builder, runner, err, cfg.NoRestartOn); err != nil { - return err - } + continue + } + + if err = handleProgramExit(builder, runner, err, cfg.NoRestartOn); err != nil { + return err } default: time.Sleep(time.Duration(cfg.PollInterval) * time.Millisecond)