Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic async support in Titanium.Network.createHTTPServer #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

du-song
Copy link

@du-song du-song commented Mar 2, 2012

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/)) {
        response.enableAsync(); // NOTE response.write() can only be invoked once.
        setTimeout(function(){
            response.write("<h1>Hello from Async</h1>");
        }, 1000);
    } else {
        response.write("<h1>Hello!</h1>");
    }
});

@Silviu-Marian
Copy link

Is there any way to recompile just the Network module?
Also, to prevent crash on second write invocation do something like this in the handler:

(function(){ 
    response._writefn = response.write; 
    response.oneoff=false; 
    response.write = function(){
        if(response.oneoff) return false;
        response.oneoff=true;
        return response._writefn.apply(this,arguments);
    };
}());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants