From 2b0b5193f853ba0c2e5b73e4c5a809b41d760576 Mon Sep 17 00:00:00 2001 From: r3inbowari Date: Fri, 3 May 2024 08:27:40 +0800 Subject: [PATCH] fix: calculation lag --- speedtest/data_manager.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/speedtest/data_manager.go b/speedtest/data_manager.go index 57a0e47..708deef 100644 --- a/speedtest/data_manager.go +++ b/speedtest/data_manager.go @@ -260,13 +260,15 @@ func (td *TestDirection) rateCapture() chan bool { prevTotalDataVolume = newTotalDataVolume if deltaDataVolume != 0 { td.RateSequence = append(td.RateSequence, deltaDataVolume) - if td.captureCallback != nil { - globalAvg := (float64(td.totalDataVolume)) / float64(time.Since(sTime).Milliseconds()) * 1000 - if td.welford.Update(globalAvg) { - go td.closeFunc() - } - td.captureCallback(td.welford.EWMA()) - } + } + // anyway we update the measuring instrument + globalAvg := (float64(td.totalDataVolume)) / float64(time.Since(sTime).Milliseconds()) * 1000 + if td.welford.Update(globalAvg) { + go td.closeFunc() + } + // reports the current rate at the given rate + if td.captureCallback != nil { + td.captureCallback(td.welford.EWMA()) } case stop := <-stopCapture: if stop {