title: Promise chain with an asynchronous operation not executing in order
body: <p>I have found other people asking about this topic but I haven't been able to get my promise chain to execute in order.</p>
  
  <p>Here is a basic reproduction of what is happening:</p>
  
  <pre><code>function firstMethod(){
  
      dbHelper.executeQuery(queryParameters).then(result =&gt; {
  
          if (result === whatIAmExpecting) {
  
              return dbHelper.doDbOperation(secondQueryParameters)}
  
          else {
  
              throw new Error('An error occurred')
  
          }})
  
          .then(doFinalOperation())
          .catch(error =&gt; {
  
          })
  }
  </code></pre>
  
  <p>In the above code doFinalOperation() is called before the then function after executeQuery() is called.</p>
  
  <p>Here is the implementation of executeQuery(): </p>
  
  <pre><code>function executeQuery(parameter) {
  
      return new Promise((resolve, reject) =&gt; {
  
          const queryToExecute = `SELECT * FROM parameter`
  
          return mySqlConnection.query(queryToExecute).then((result) =&gt; {
  
              resolve(result)
  
          }).catch(error =&gt; {
  
              reject(error)
          })
      })
  </code></pre>
  
  <p>And here is the implementation of of the  mySqlConnection.query method: </p>
  
  <pre><code>function query(queryString){
  
   return new Promise((resolve, reject) =&gt;
      {
  
    initConnection()
  
    connection.connect()
  
      require('bluebird').promisifyAll(connection)
  
       return connection.queryAsync(queryString).then(function(results) {
  
          connection.end();
  
          resolve(results)
  
          }).catch(error =&gt; {
  
                  reject(error)
              })
        })
  </code></pre>
  
  <p>It seems like I have incorrectly implemented the executeQuery() method. The database operation in the mySqlConnection.query is asychronous and I can see that's where the chain of promises stops happening in the expected order.</p>
  
  <p><strong>My question in a nutshell:</strong> How do I make the my chain of promises execute in order, and how I do stop a then() method from being executed before the previous Promise has called resolve() or reject()?</p>
  
  <p>Thanks in advance. </p>