watcher exit

This commit is contained in:
alessio 2016-09-17 21:07:22 +02:00
parent 01cb2287fb
commit 608a1a64d0
2 changed files with 9 additions and 10 deletions

View File

@ -44,8 +44,8 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
}
close(runner)
execOutput := bufio.NewScanner(stdout)
execError := bufio.NewScanner(stderr)
execOutput, execError := bufio.NewScanner(stdout), bufio.NewScanner(stderr)
stopOutput, stopError := make(chan bool, 1), make(chan bool, 1)
scanner := func(stop chan bool, output *bufio.Scanner, isError bool) {
for output.Scan() {
@ -60,7 +60,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
log.Println(pname(p.Name, 3), ":", BlueS(output.Text()))
}
if p.Watcher.Output["file"] {
path := filepath.Join(p.base, Bp.Files["output"])
path := filepath.Join(p.base, B.Files["output"])
f := create(path)
t := time.Now()
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
@ -71,8 +71,6 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
}
close(stop)
}
stopOutput := make(chan bool, 1)
stopError := make(chan bool, 1)
go scanner(stopOutput, execOutput, false)
go scanner(stopError, execError, true)
@ -86,7 +84,6 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
return nil
}
}
}
// GoBuild is an implementation of the "go build"

View File

@ -25,7 +25,7 @@ func (p *Project) watching() {
if err != nil {
log.Println(strings.ToUpper(pname(p.Name, 1)), ":", Red(err.Error()))
}
channel := make(chan bool, 1)
channel, exit := make(chan bool, 1), make(chan bool, 1)
if err != nil {
log.Println(pname(p.Name, 1), ":", Red(err.Error()))
}
@ -35,7 +35,7 @@ func (p *Project) watching() {
}
defer end()
p.cmd()
p.cmd(exit)
err = p.walks(watcher)
if err != nil {
fmt.Println(pname(p.Name, 1), ":", Red(err.Error()))
@ -83,6 +83,8 @@ func (p *Project) watching() {
}
case err := <-watcher.Errors:
log.Println(Red(err.Error()))
case <-exit:
return
}
}
}
@ -141,7 +143,7 @@ func (p *Project) fmt(path string) error {
}
// Cmd calls an wrapper for execute the commands after/before
func (p *Project) cmd() {
func (p *Project) cmd(exit chan bool) {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
cast := func(commands []string) {
@ -163,7 +165,7 @@ func (p *Project) cmd() {
if len(p.Watcher.After) > 0 {
cast(p.Watcher.After)
}
os.Exit(1)
close(exit)
}
}
}()