debounce function for golang

for my presentation tool slide-serve i used fsnotify to watch for changes to reload the browser. But for whatever reason, the events always came in doubled… so i tried to port the idea behind the underscore or RX debounce function to golang. This is the solution i came up with: func debounce(interval time.Duration, input chan string, cb func(arg string)) { var item string timer := time.NewTimer(interval) for { select { case item = <-input: timer....

Tags

comments powered by Disqus