use ticker (#553)

* use ticker

* stop the ticker
This commit is contained in:
Raphael Deem 2018-05-15 07:45:41 -07:00 committed by Martin Linkhorst
parent e664bde484
commit daeda2ed53

View File

@ -66,14 +66,15 @@ func (c *Controller) RunOnce() error {
// Run runs RunOnce in a loop with a delay until stopChan receives a value.
func (c *Controller) Run(stopChan <-chan struct{}) {
ticker := time.NewTicker(c.Interval)
defer ticker.Stop()
for {
err := c.RunOnce()
if err != nil {
log.Error(err)
}
select {
case <-time.After(c.Interval):
case <-ticker.C:
case <-stopChan:
log.Info("Terminating main controller loop")
return