title: Trouble dealing with asynchronous non-blocking model
body: <p>I'm having trouble with getting around asynchronous model of node, I have this function:</p>
  
  <pre><code>function getstream() {
  
      console.log('calling testAvail, Avail value is:' + available);
      testAvailability();
      console.log('Available:'+available);
      if (available || SelfSharing) {
  
           // Do something
           setDefaults();
  
           return;
      }
  }
  </code></pre>
  
  <p>Which calls testAvailability() function defined as:</p>
  
  <pre><code>function testAvailability()
  {
      console.log('entered test');
      var stat;
      var socket = io.connect('http://somedomain.com');
      socket.on('error', function() {
  
          console.log('There was an error at server end please try again');
          // chrome.runtime.reload();
  
          setTimeout(chrome.runtime.reload(),3000);
          //here i change options
          //socket = io.connect(host, options);
      });
      socket.emit('available');
      socket.on('available', function (status) {
          console.log('got status from server which is:'+ status);
          available=status;
          console.log("inside the socket.on"+available);
          console.log('leaving test, do you see any got status above?');
      });
  }
  </code></pre>
  
  <p>I want getstream() to continue from where it left after testAvailability() is done and <code>available</code> variable has it's value set.</p>