title: How to call a function after javascript async function with promises?
body: <p>So I have a function where I'm chaining promises to fetch different data which would be like this.</p>
  
  <pre><code>that = this;    
  that.load = function load() {
  getEmployeeDetails(id)
      .then(function() {
          return validateEmployeeDetails([name, age, address]);
      })
      .spread(function (nameData, ageData, addressData) {
      that.name = "Name: " + nameData;
      that.age = "Age: " + ageData;
      that.address = "Address: " + addressData;
      })
      .then(function() {
          return someService.getDesignation(id);
      })
      .then(function(desig) {
          that.designation = desig;
      })
      .catch(function(err) {
          throw error;
      })
      .done();
  };
  </code></pre>
  
  <p>I've another function where I have to call the load function</p>
  
  <pre><code>that.openEmployee = function openEmployee() {
      getEmployeeSession()
      .then(function getSessionData(res) {
          if(res.status === 200) {
              doSomething();
          }
      })
      .catch(function() {
          throw error;
      })
      .done();
  };
  </code></pre>
  
  <p>Now I have to call the load function before the doSomething function. I tried using promises and also using events. But the problem is, it executes the spread part of the load and then calls the doSomething and then goes on executing the then blocks in load function. Whereas, I want to call the doSomething method after the last then in the load function is executed.
  Thanks in advance.</p>