Skip to content

Commit

Permalink
use ticker (#553)
Browse files Browse the repository at this point in the history
* use ticker

* stop the ticker
  • Loading branch information
r0fls authored and linki committed May 15, 2018
1 parent e664bde commit daeda2e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit daeda2e

Please sign in to comment.