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) {
|
func eventLoop(pinger *probing.Pinger) {
|
||||||
ticker := time.NewTicker(time.Second * 4)
|
ticker := time.NewTicker(time.Second * 4)
|
||||||
|
defer ticker.Stop()
|
||||||
|
defer pinger.Stop()
|
||||||
|
|
||||||
// Setup signals on term and interrupt.
|
// Setup signals on term and interrupt.
|
||||||
sig := make(chan os.Signal, 1)
|
sig := make(chan os.Signal, 1)
|
||||||
|
|
@ -33,8 +35,6 @@ func eventLoop(pinger *probing.Pinger) {
|
||||||
select {
|
select {
|
||||||
// Got signal. stop pinger and exit goroutine
|
// Got signal. stop pinger and exit goroutine
|
||||||
case <-sig:
|
case <-sig:
|
||||||
ticker.Stop()
|
|
||||||
pinger.Stop()
|
|
||||||
return
|
return
|
||||||
// Ticker ticks. print stats.
|
// Ticker ticks. print stats.
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue