title: how to wait with setTimeout until a variable get loaded and, at the same time, receive HTTP requests!
body: <p>I' ve made a in JavaScript function to check every 100 ms if a global variable is loaded.
  When the variable will be loaded the function will return the value of the
  variable as shown below. In my code I use an HTTP server in JavaScript,
  and the variable will be loaded when a specific HTTP request with specific
  headers arrive to my server. </p>
  
  <pre><code>function checkVariable()
  {
      if ( myvar != null )
      {
              return myVar;
      }
      else
      {
              window.setTimeout("checkVariable();",100);
      }
  } 
  </code></pre>
  
  <p>I use this function in a piece of code like this:</p>
  
  <pre><code>// arithmetis operations... [1]
  
  myVar = checkVariable();
  
  // arithmetic operations that use myVar [2]
  </code></pre>
  
  <p>myVar is initiated with null. The problem is that the arithmetic operations in [2] are done before myVar got its value. Instead, I want my code to wait until myVar get
  its value, and then to continue with the operations.</p>
  
  <p>Before trying the setTimeout function, I tried to make the code waiting using a while loop, but the problem then was that the HTTP server couldn't receive any HTTP request due to the continuously execution of the while loop!</p>
  
  <p>Could someone help me to solve this problem?</p>
  
  <p>Thank you in advance!</p>