Go package for Debounce and Throttle functions.
See stackoverflow answers for more details about what is throttle and debounce.
go get github.com/chneau/slow
...
i := 0
fn := func() {
i++
}
options := &slow.Options{
Trailing: true,
Leading: true,
MaxWait: time.Millisecond * 500,
}
// options = nil // can be null, see defaults
throttled := slow.Throttle(fn, time.Millisecond*50, options)
debounced := slow.Debounce(fn, time.Millisecond*50, options)
// the returned functions will be debounced / throttled.
// so some calls will be no-op depending on the options
throttled()
throttled()
...
Thanks to lodash from where the implementation comes from.