From a3ad285a133daccc59e1cc847fc11690344fadc9 Mon Sep 17 00:00:00 2001 From: "minjea.lee" Date: Tue, 20 Feb 2024 13:45:58 +0900 Subject: [PATCH] polishing --- retry.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/retry.go b/retry.go index 002ecd47..dd047d8f 100644 --- a/retry.go +++ b/retry.go @@ -306,12 +306,6 @@ func (th *throttle) throttledFunc() { } } -func (th *throttle) invokeFunctions() { - for _, f := range th.callbacks { - go f() - } -} - func (th *throttle) purge(forcePurge bool) { th.mu.Lock() defer th.mu.Unlock() @@ -321,15 +315,16 @@ func (th *throttle) purge(forcePurge bool) { } if th.needInvoke || forcePurge { - th.invokeFunctions() + for _, f := range th.callbacks { + go f() + } + th.needInvoke = false th.timer = time.AfterFunc(th.interval, func() { th.purge(false) }) } else { th.timer = nil } - - th.needInvoke = false } // NewThrottle creates a throttled instance that invokes given functions only once in every interval.