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:
parent
5d1967e357
commit
94491434bc
@ -45,13 +45,15 @@ func main() {
|
|||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
signal.Notify(c, syscall.SIGTERM)
|
signal.Notify(c, syscall.SIGTERM)
|
||||||
|
wait := make(chan bool)
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-c:
|
case <-c:
|
||||||
fmt.Println("get interrupted")
|
fmt.Println("get interrupted")
|
||||||
break loop
|
signal.Stop(c)
|
||||||
|
quit <- wait
|
||||||
case res := <-onRecv:
|
case res := <-onRecv:
|
||||||
if _, ok := results[res.addr.String()]; ok {
|
if _, ok := results[res.addr.String()]; ok {
|
||||||
results[res.addr.String()] = res
|
results[res.addr.String()] = res
|
||||||
@ -67,10 +69,10 @@ loop:
|
|||||||
}
|
}
|
||||||
case err := <-errch:
|
case err := <-errch:
|
||||||
fmt.Println("Ping failed: %v", err)
|
fmt.Println("Ping failed: %v", err)
|
||||||
|
signal.Stop(c)
|
||||||
|
quit <- wait
|
||||||
|
case <-wait:
|
||||||
break loop;
|
break loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wait := make(chan bool)
|
|
||||||
quit <- wait
|
|
||||||
<-wait
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user