Просмотр исходного кода

fix restart on file change when autorestart is disabled.

you had to save the file twice to make it restart then. (because the
first time the runner goroutine would quit and then the second time
restart would actually restart the goroutine and then it would work.)
Lucas Stadler лет назад: 11
Родитель
Сommit
d8034f2055
1 измененных файлов с 10 добавлено и 6 удалено
  1. 10 6
      go/qst.go

+ 10 - 6
go/qst.go

112
}
112
}
113
113
114
type Runner struct {
114
type Runner struct {
115
	cmd      *exec.Cmd
116
	shellCmd string
117
	started  bool
118
	restart  bool
115
	cmd        *exec.Cmd
116
	shellCmd   string
117
	started    bool
118
	restart    bool
119
	restarting bool
119
}
120
}
120
121
121
func MakeRunner(shellCmd string, restart bool) *Runner {
122
func MakeRunner(shellCmd string, restart bool) *Runner {
122
	return &Runner{nil, shellCmd, false, restart}
123
	return &Runner{nil, shellCmd, false, restart, false}
123
}
124
}
124
125
125
func (r *Runner) Start() error {
126
func (r *Runner) Start() error {
145
			log.Printf("%s finished: %s", r.shellCmd, result)
146
			log.Printf("%s finished: %s", r.shellCmd, result)
146
147
147
			time.Sleep(*delay)
148
			time.Sleep(*delay)
148
			if !r.restart {
149
			if !r.restarting && !r.restart {
149
				r.started = false
150
				r.started = false
150
				break
151
				break
151
			}
152
			}
153
154
			r.restarting = false
152
		}
155
		}
153
	}()
156
	}()
154
157
164
}
167
}
165
168
166
func (r *Runner) Restart() error {
169
func (r *Runner) Restart() error {
170
	r.restarting = true
167
	if r.started {
171
	if r.started {
168
		return r.Kill()
172
		return r.Kill()
169
	} else {
173
	} else {