title: javascript es6 promise to call async actions in while loop
body: <p>I have a function like:</p>
  
  <pre><code>function callApi(url){
      return fetch(url).then(response =&gt; {return response.json()}
         ).then(response =&gt; {return response})
  }
  
  function myFunction() {
      var status = null;
      while (status != "complete") {
          setTimeout(function(){
              callApi('myurl').then(response =&gt; {
                 status = response.status
              }
           }, 5000)
      }
  </code></pre>
  
  <p>Here I simply want to check if I am getting desired status from the api call.</p>
  
  <p>Untill I get desired status from the api call I want to check on every 5 seconds..</p>
  
  <p>But this is not working.. 
  I have googled but not understood the solution according to my need.
  It would be very helpful if anyone could answer this.</p>
  
  <p>I am new to javascript. I have looked somewhere about <code>es6</code> promise. 
  It would be very great if someone could explain this ..</p>
  
  <p>thank you</p>