feat: add Throttle function

This commit is contained in:
dudaodong
2024-08-09 14:28:15 +08:00
parent 0bc5f82554
commit 0f9764f41e
5 changed files with 228 additions and 16 deletions

View File

@@ -200,3 +200,24 @@ func ExampleAcceptIf() {
// 0
// false
}
func ExampleThrottle() {
callCount := 0
fn := func() {
callCount++
}
throttledFn := Throttle(fn, 1*time.Second)
for i := 0; i < 5; i++ {
throttledFn()
}
time.Sleep(1 * time.Second)
fmt.Println(callCount)
// Output:
// 1
}