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

Simplify RunLoop() call and add Stop()

This commit is contained in:
Tatsushi Demachi
2014-08-03 00:00:15 +09:00
parent a97a44952e
commit 88c0127fe9
3 changed files with 47 additions and 50 deletions

View File

@@ -40,20 +40,18 @@ func main() {
})
p.MaxRTT = time.Second
quit, errch := p.RunLoop()
errch := p.RunLoop()
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")
signal.Stop(c)
quit <- wait
break loop
case res := <-onRecv:
if _, ok := results[res.addr.String()]; ok {
results[res.addr.String()] = res
@@ -69,10 +67,9 @@ loop:
}
case err := <-errch:
fmt.Println("Ping failed: %v", err)
signal.Stop(c)
quit <- wait
case <-wait:
break loop;
break loop
}
}
signal.Stop(c)
p.Stop()
}