Back to Lo

Core Newdebounce

docs/data/core-newdebounce.md

1.53.0413 B
Original Source

Creates a debounced function that delays invoking the callbacks until after the wait duration has elapsed since the last call. Returns the debounced function and a cancel function.

go
debounce, cancel := lo.NewDebounce(
    100 * time.Millisecond,
    func() {
        println("Called once after debounce!")
    },
)

for i := 0; i < 10; i++ {
    debounce()
}

time.Sleep(200 * time.Millisecond)
cancel()