Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created June 23, 2011 05:00
Show Gist options
  • Save aaronksaunders/1041936 to your computer and use it in GitHub Desktop.
Save aaronksaunders/1041936 to your computer and use it in GitHub Desktop.
use only one instance of the httpClient?
var serviceList = [];
var xhr;
var tmpSvc = fetchServicesByProfile(Titanium.UI.currentWindow.profileid);
for(i=0;i<tmpSvc.length;i++)
{
//Populate serviceList array.
}
function processServiceList(index)
{
var serviceinfo = serviceList[index];
// use only one httpclient
if ( xhr == null ) {
xhr = Ti.Network.createHTTPClient();
}
var requestURI = '<appropriate uri here>';
xhr.open("GET",requestURI);
xhr.onload = function()
{
if (this.readyState == xhr.DONE && this.status == 200)
{
var doc = this.responseXML.documentElement;
if (index < serviceList.length - 1)
{
processServiceList(index + 1);
}
else
{
//Ti.API.debug('done with this.');
//loadStreamsIntoTableView(Titanium.UI.currentWindow.profileid);
}
}
}
xhr.send();
}
processServiceList(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment