title: async / wait in nested functions
body: <p>I'm trying to display a nested countdown, implemented in two nested loops. </p>
  
  <p>The full, working code can be found in this <a href="https://jsfiddle.net/utw9sr86/1/" rel="nofollow noreferrer">js.fiddle</a>. Two relevant parts are the following:</p>
  
  <pre><code>function sleep(ms) 
  {
      return new Promise(resolve =&gt; setTimeout(resolve, ms));
  }
  
  async function main()
  {
      while(true)
      {
        clearScreen();
  
          for (var i = 10; i &gt; 0; i--) 
          {
              print(i);
  
              await sleep(1000);
  
              clearScreen();
  
              for (var j = 3; j &gt; 0; j--) 
              {
                  print(j);
  
                  await sleep(1000);
  
                  clearScreen();
              }
          }
      }
  }
  
  main();
  </code></pre>
  
  <p>This works as expected. However, when I try to refactor the most inner loop into a seperate function like this</p>
  
  <pre><code>async function innerLoop()
  {
      for (var j = 3; j &gt; 0; j--) 
      {
          print(j);
  
          await sleep(1000);
  
          clearScreen();
      }
  }
  </code></pre>
  
  <p>and call this function inside <code>main()</code> the coutndown doesn't work as expected. (Corresponding code: <a href="https://jsfiddle.net/utw9sr86/" rel="nofollow noreferrer">js.fiddle</a>).</p>
  
  <p>How can I make async / await work when using it inside nested functions to implememt this? I want to avoid having everything in one big function.</p>