title: How to wait until a predicate condition becomes true in JavaScript?
body: <p>I have javascript function like this:</p>
  
  <pre><code>function myFunction(number) {
  
      var x=number;
      ...
      ... more initializations
      //here need to wait until flag==true
      while(flag==false)
      {}
  
      ...
      ... do something
  
  }
  </code></pre>
  
  <p>The problem is that the javascript is stuck in the while and stuck my program. so my question is how can I wait in the middle of the function until flag is true without "busy-wait"?</p>