Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debounce ¶
func Debounce(clock cage_time.Clock, interval std_time.Duration, f func(interface{})) func(interface{})
Debounce returns a debounced version of the input function.
One goroutine with a for-select loop is created for each returned function, RF, to communicate with. When RF is called, all it does is send the input data to the for-select in the goroutine. If a RF-stateful timer is nil, a timer is created with the debounce interval. But if the timer is non-nil, it is reset with the debounce interval. So if the RF is called twice within a total of two seconds, and the debounce interval is three seconds, the first RF call creates/starts the timer and the second call resets the timer. If the RF is no longer called and the timer is allowed to finish, the input function is finally invoked and the timer is set back to nil.
Origin:
https://gist.github.com/leolara/d62b87797b0ef5e418cd#gistcomment-2243168 https://gist.github.com/alcore
Changes:
- Provide interface{} argument as optional approach to link an invocation to an attempted value.
- Resolve timer data race.
- Inject a mockable clock.
- Add test.
Types ¶
This section is empty.