title: Is there a way to do repetitive tasks at intervals?
body: <p>Is there a way to do repetitive background tasks in Go?  I'm thinking of something like <code>Timer.schedule(task, delay, period)</code> in Java.  I know I can do this with a goroutine and <code>Time.sleep()</code>, but I'd like something that easily stopped.</p>
  
  <p>Here's what I got, but looks ugly to me.  Is there a cleaner/better way?</p>
  
  <pre><code>func oneWay() {
      var f func()
      var t *time.Timer
  
      f = func () {
          fmt.Println("doing stuff")
          t = time.AfterFunc(time.Duration(5) * time.Second, f)
      }
  
      t = time.AfterFunc(time.Duration(5) * time.Second, f)
  
      defer t.Stop()
  
      //simulate doing stuff
      time.Sleep(time.Minute)
  }
  </code></pre>