title: Understanding javascript promise used with setTimeout and setInterval
body: <p>Can someone help me understand these 2 lines of code and improve them to actually allow me to stop the repeats?</p>
  
  <pre><code>var wait = ms =&gt; new Promise(r =&gt; setTimeout(r, ms));
  var repeat = (ms, func) =&gt; new Promise(r =&gt; (setInterval(func, ms), wait(ms).then(r)));
  
  repeat(1000, () =&gt; Promise.all([myfunction()])
    .then(...)
  </code></pre>