title: Titanium Studio hold function execution until another function completes
body: <p>Hey all I'm trying to get a window populated with a table view that is populated from a network function in Titanium Studio, build: 2.1.1.201207271312. I have the data being fetched properlybut the problem is that the program continues to run without waiting for the table view to be populated properly. Here's the code:</p>
  
  <p>ui.js:</p>
  
  <pre><code>bs.ui.createTransitRoutesListWindow = function() {
  
      var winbsRoutesList = Titanium.UI.createWindow({
      });
      var tv2 = Ti.UI.createTableView();
      tv2 = bs.ui.createbsRouteListTableView();
  
      winbsRoutesList.add(tv2);       
  };
  
  bs.ui.createbsRouteListTableView = function() {
  
      var tv = Ti.UI.createTableView();       
  
      Ti.API.info('populating data');
          var busStopList = bs.db.routeStopList(); 
  
          tv.setData(busStopList);
  
          return tv;
  
  };
  </code></pre>
  
  <p>db.js:</p>
  
  <pre><code> bs.db.routeStopList = function() {
  var stoplist = [];
  
  bs.net.getRoutes(function(data) {
      Ti.API.info('data length: '+data.length);
      for (var i = 0;i&lt;data.length;i++) {
          stoplist.push({
              title:data[i].stopName,
              id: i
          });
      }
  
  });
  return stoplist;
   }
  </code></pre>
  
  <p>network.js</p>
  
  <pre><code>bs.net.getRoutes = function(_cb) { 
  
      var xhr = Titanium.Network.createHTTPClient();
      xhr.onload = function() {  
          _cb(JSON.parse(this.responseText));
  
      Ti.API.info(this.responseText)
      };
      xhr.onerror = function(event) {
      }
      xhr.open("GET","&lt;URL to valid JSON&gt;", true);  
      //+ Ti.App.Properties.getString('currentBus','This is a string default')
      xhr.send();
  
  };
  </code></pre>