Files
kubeshark/cli/debounce/debounce.go
nimrod-up9 620f046a26 TRA-3257 Dynamic tappers (#57)
* Defer cleanup.

* Split createMizuResources into two functions.

* Re-create daemonset when changes to tapped pods occur.

* Reordered imports.

* Use Printf instead of Println.

* Workaround for variable scope.

* WIP Apply daemonset instead of create.

* Whitespaces.

* Fixed: Using the right types for Apply.

* Fixed missing pod IP by adding a delay.

* Debounce pod restart.

* Proper field manager name.
2021-05-26 17:25:12 +03:00

43 lines
720 B
Go

package debounce
import (
"time"
)
func NewDebouncer(timeout time.Duration, callback func()) *Debouncer {
var debouncer Debouncer
debouncer.setTimeout(timeout)
debouncer.setCallback(callback)
return &debouncer
}
type Debouncer struct {
callback func()
running bool
timeout time.Duration
timer *time.Timer
}
func (d *Debouncer) setTimeout(timeout time.Duration) {
// TODO: Return err if d.running
d.timeout = timeout
}
func (d *Debouncer) setCallback(callback func()) {
callbackWrapped := func() {
callback()
d.running = false
}
d.callback = callbackWrapped
}
func (d *Debouncer) SetOn() {
if d.running == true {
return
}
d.running = true
d.timer = time.AfterFunc(d.timeout, d.callback)
}