From 16bb1169d3ecd3acb79a162bad6644af0ffc6019 Mon Sep 17 00:00:00 2001 From: zekroTJA Date: Mon, 26 Oct 2020 11:36:37 +0100 Subject: [PATCH] add pinger reset to re-use instance --- ping.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ping.go b/ping.go index e1c09ee..86d632c 100644 --- a/ping.go +++ b/ping.go @@ -518,6 +518,16 @@ func (p *Pinger) Stop() { } } +// Reset sets the RTTs and the sent and received counts +// back to zero so that Run can be re-used on the same +// instance. +func (p *Pinger) Reset() { + p.done = make(chan bool) + p.rtts = make([]time.Duration, 0) + p.PacketsSent = 0 + p.PacketsRecv = 0 +} + func (p *Pinger) finish() { handler := p.OnFinish if handler != nil {