1
0
mirror of https://github.com/taigrr/go-fastping synced 2025-01-18 05:03:15 -08:00

Change ping command loop like a RunLoop example

This commit is contained in:
Tatsushi Demachi 2014-04-22 00:15:03 +09:00
parent 5d1967e357
commit 94491434bc

View File

@ -45,13 +45,15 @@ func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
wait := make(chan bool)
loop:
for {
select {
case <-c:
fmt.Println("get interrupted")
break loop
signal.Stop(c)
quit <- wait
case res := <-onRecv:
if _, ok := results[res.addr.String()]; ok {
results[res.addr.String()] = res
@ -67,10 +69,10 @@ loop:
}
case err := <-errch:
fmt.Println("Ping failed: %v", err)
signal.Stop(c)
quit <- wait
case <-wait:
break loop;
}
}
wait := make(chan bool)
quit <- wait
<-wait
}