foo := func() {
// do somthing anoying
}
var options *DebounceOptions // if nil, will have default options
debounced, cancel := gobounce.Debounce(foo, 2*time.Second, options)
defer cancel() // should be called to dispose timers and flush
debounced()
debounced()
debounced()
debounced()
debounced()
...
// after 2 seconds...
...
// foo called only once!
foo := func() {
// do somthing exausting
}
var options *ThrottleOptions // if nil, will have default options
throttled, cancel := gobounce.Throttle(foo, 2*time.Second, options)
defer cancel() // should be called to dispose timers and flush
// ------------- 00:00:00
throttled() // - 00:01:00
throttled() // - 00:02:00 - called!
throttled() // - 00:03:00
throttled() // - 00:04:00 - called!
throttled() // - 00:05:00
throttled() // - 00:06:00 - called!
// ------------- 00:07:00
Idan Izicovich