ソースを参照

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 年 前
コミット
d8034f2055
共有1 個のファイルを変更した10 個の追加6 個の削除を含む
  1. 10 6
      go/qst.go

+ 10 - 6
go/qst.go

@ -112,14 +112,15 @@ func runCmd(file string, runner *Runner) {
112 112
}
113 113
114 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 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 126
func (r *Runner) Start() error {
@ -145,10 +146,12 @@ func (r *Runner) Start() error {
145 146
			log.Printf("%s finished: %s", r.shellCmd, result)
146 147
147 148
			time.Sleep(*delay)
148
			if !r.restart {
149
			if !r.restarting && !r.restart {
149 150
				r.started = false
150 151
				break
151 152
			}
153
154
			r.restarting = false
152 155
		}
153 156
	}()
154 157
@ -164,6 +167,7 @@ func (r *Runner) Kill() error {
164 167
}
165 168
166 169
func (r *Runner) Restart() error {
170
	r.restarting = true
167 171
	if r.started {
168 172
		return r.Kill()
169 173
	} else {