feat: add Throttle function

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

No files matched your search

+21
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
}