Back to Lo

Core Newthrottlewithcount

docs/data/core-newthrottlewithcount.md

1.53.0290 B
Original Source

Creates a throttled function with a per-interval invocation limit.

go
throttle, reset := lo.NewThrottleWithCount(
    100*time.Millisecond,
    3,
    func() {
        println("tick")
    },
)

for i := 0; i < 10; i++ {
    throttle();
    time.Sleep(30*time.Millisecond)
}

reset()