title: How to run 2 lines of Javascript in sequence - async/promises/callbacks
body: <p>I need to run two (or more) lines of code in sequence in vanilla javascript.</p>
  <p>Each invokes calls to routines (aka top level functions, which have a purpose of performing procedural steps rather than calculating a result). These in turn call multiple others.</p>
  <pre><code>function fMasterProcedure() {
      fSubProcedure1();
      fSubProcedure2();
      ... etc
  }
  </code></pre>
  <p>Suppose the code for fSubProcedure1() is as follows (for this illustration):</p>
  <pre><code>function fSubProcedure1() {
      fSubSubProcedure1_1();  // Normal
      fSubSubProcedure1_2();  // Async
      fSubSubProcedure1_3();  // Normal
      fSubSubProcedure1_4();  // Async
      fSubSubProcedure1_5();  // Normal
  }
  </code></pre>
  <p>This is literally the same question as here <a href="https://stackoverflow.com/questions/17204537/how-to-run-sequence-functions-in-javascript">how to run sequence functions in javascript</a>, although the answers provided there do not show how to do it, and there have been syntax updates in the years since in relation to promises and asynchronous functions.</p>
  <p>These days the answer seems to be promises and async/await... or is it just callbacks without using promises?</p>
  <p>I have read many descriptions and tutorials on promises, including here.</p>
  <p>However, I end up with code like this:</p>
  <pre><code>function fMasterProcedure() {
      return (new Promise(function(resolve, reject) {
          fSubProcedure1();
          setTimeout(function () {
              resolve();
          }, 0);
      })).then(function(result) {
          fSubProcedure2();
      });
  }
  </code></pre>
  <p>As you can see, it adds 400% more lines unnecessarily and still doesn't work reliably.</p>
  <p>Is there a more efficient way to write this, or a more appropriate way?</p>
  <p>(The requirement is to run <code>fSubProcedure2</code> after <code>fSubProcedure1</code> (and any of its child processes) are completed in full. I am trying to move from &quot;that's not how JS works&quot; to &quot;here's how to make JS achieve that requirement&quot;).</p>
  <p>I'm trying to get the good understanding so I can apply it to a whole project approach - there are many examples within, of each.</p>