appcelerator/titanium_desktop — pull request #6 by freewizard (2012-03-02 19:03:10+00:00)
Title: basic async support in Titanium.Network.createHTTPServer

call response.enableAsync() will allow response to be written a while after the server callback is returned.

var httpServer = Titanium.Network.createHTTPServer();
httpServer.bind(8080, function(request, response)
{
Titanium.API.debug("Got request for URI: " + request.getURI());
response.setContentType("text/html");
if (request.getURI().match(/async/)) {
document.title = " loading";
response.enableAsync(); // NOTE response.write() can only be invoked once.
setTimeout(function(){
response.write("

Hello from Async

");
document.title = "loaded";
}, 1000);
} else {
response.write("

Hello!

");
}
});