time

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2020 License: MPL-2.0 Imports: 2 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL