Files
lo/docs/data/core-newdebounceby.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

955 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
NewDebounceBy newdebounceby retry.go#L137 core concurrency https://go.dev/play/p/Izk7GEzZm2Q
core#concurrency#newdebounceby
core#concurrency#newdebounce
core#concurrency#newthrottle
core#concurrency#newthrottleby
core#concurrency#newdebounceby
10
func NewDebounceBy[T comparable](duration time.Duration, f ...func(key T, count int)) (func(key T), func(key T))

Creates a debounced function per key that delays invoking callbacks until after the wait duration has elapsed for that key. Returns a per-key debounced function and a per-key cancel function.

debounce, cancel := lo.NewDebounceBy[string](
    100*time.Millisecond,
    func(key string, count int) {
        println(key, count)
    },
)

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

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