Skip to content

Commit

Permalink
polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
minjea.lee committed Feb 20, 2024
1 parent 546826d commit a3ad285
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down

0 comments on commit a3ad285

Please sign in to comment.