mirror of
https://github.com/pnx/pinger.git
synced 2026-06-16 03:24:54 +02:00
main.go: defer cleanup functions in eventLoop()
This commit is contained in:
parent
dfc7865bc1
commit
ede1205501
1 changed files with 2 additions and 2 deletions
4
main.go
4
main.go
|
|
@ -24,6 +24,8 @@ func printStats(pinger *probing.Pinger) {
|
|||
|
||||
func eventLoop(pinger *probing.Pinger) {
|
||||
ticker := time.NewTicker(time.Second * 4)
|
||||
defer ticker.Stop()
|
||||
defer pinger.Stop()
|
||||
|
||||
// Setup signals on term and interrupt.
|
||||
sig := make(chan os.Signal, 1)
|
||||
|
|
@ -33,8 +35,6 @@ func eventLoop(pinger *probing.Pinger) {
|
|||
select {
|
||||
// Got signal. stop pinger and exit goroutine
|
||||
case <-sig:
|
||||
ticker.Stop()
|
||||
pinger.Stop()
|
||||
return
|
||||
// Ticker ticks. print stats.
|
||||
case <-ticker.C:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue