title: Recursion in Promises
body: <p>I am writing some software where one can execute a list of actions. each of these actions basically is a Promise.
  Each action might have a timer Trigger (where the next action is triggered when the timer ran down). Also, the list of actions might be loopable.</p>
  <p>Now it might be possible, that a list of actions e.g. consists out of 2 items, each is executed 0 seconds after finishing the last one, and looping is enabled, thus actually generating an infinite loop.</p>
  <p>This is no error in the application and thus be possible to do. My Code looks (extremely simplified) like this at the moment:</p>
  <pre><code>const actions = [...] // (() =&gt; Promise&lt;void&gt;)[]
  const current = 0
  const loop = true
  const autoTrigger = true
  
  const go() {
     if(current &gt; actions.length &amp;&amp; loop) current = 0
     current ++ 
     return Promise.resolve().then(() =&gt; {
        return actions[current - 1]()
     }).then(() =&gt; {
        if(autoTrigger) return go()
        return Promise.resolve()
     })
  }
  </code></pre>
  <p>Is this code safe to run, assuming that it might not be aborted until it iterated a few hundred thousand times, or might it cause an error because the recursion gets too deep?</p>