title: Start and Stop core.async Interval
body: <p>consider the following core-async code. It prints the string "tick" every 2 seconds:</p>
  
  <pre><code>(go-loop []
    (&lt;! (timeout 2000))
    (prn "tick")
    (recur))
  </code></pre>
  
  <p>I'm looking for a possibility to start and stop the interval from outside via functions.</p>
  
  <p>The only thing that came to my mind was this:</p>
  
  <pre><code>(def running (atom false))
  
  (defn start []
    (reset! running true)
    (go (loop []
           (&lt;! (timeout 2000))
           (prn "tick")
           (when @running (recur)))))
  
  (defn stop []
    (reset! running false))
  </code></pre>
  
  <p>Is this the way to go? Or would you do something else?</p>