title: Working with promises inside an if/else
body: <p>I have a conditional statement in which I need to perform one of two operations, then continue after whichever operation has resolved.  So my code currently looks as follows:</p>
  
  <pre><code>if (shoud_do_thing_a) { //should_do_thing_a is just a variable that determines which function to call. it is not a promise
    do_thing_a()
  } else {
    do_thing_b()
  }
  
  // more code
  </code></pre>
  
  <p>The issue is that both <code>do_thing_a</code> and <code>do_thing_b</code> return promises, and I can't move on until whichever gets executed has resolved.  The best way I've come up with to solve this is like this:</p>
  
  <pre><code>var more_code = function () { 
    // more code
  }
  
  if (shoud_do_thing_a) {
    do_thing_a().then(more_code)
  } else {
    do_thing_b().then(more_code)
  }
  </code></pre>
  
  <p>I don't like this structure.  It's difficult to follow because you need to jump around to find where <code>more_code</code> is defined (imagine I have this type of control flow in several locations), rather than simply being able to continue reading.</p>
  
  <p>Is there a better way to deal with this type of thing in javascript?</p>