title: Make JS Promise that resolves once a value is returned
body: <p>I have a react apollo graphql query which is <code>{..., loading: true}</code>, and after about 1 second it will be <code>loading: false</code>. I want the <code>new Promise</code> to <code>resolve()</code> after <code>loading: false</code>. </p>
  
  <p>Do I need to specify how often it checks? Like every 100 ms? Do I use a <code>while</code> loop? If you could write the code I would greatly appreciate it, I've already tried for hours without success. </p>
  
  <p>Example:</p>
  
  <pre><code>return new Promise((resolve, reject) =&gt; {
     while (this.props.query.loading){
       //rerun function
     }
     resolve(this.props.query.data)
  }).then((data)=&gt;{
    //run my code
     this.setState({data: data});
  });
  </code></pre>
  
  <p><strong>EDIT:
  My issue is solved,</strong> but the question isn't answered. No need to answer now though unless you think it would help someone else. </p>