stackp / promisejs

Lightweight javascript implementation of promises.
443 stars 127 forks source link

Support timeout for ajax requests #4

Closed grobmeier closed 11 years ago

grobmeier commented 12 years ago

It would be fantastic if promise.js would support a timeout feature.

In my case (mobile app with phonegap) I sometimes loose connectivity. Therefore it would be great if the request would be finished after a while and an error is thrown (or something like that)

stackp commented 12 years ago

Yes, absolutely. I'm digging into this.

grobmeier commented 12 years ago

Thank you! I am available for testing.

stackp commented 11 years ago

@grobmeier I've had this branch lying around for months without getting around to testing it. Are you still available for testing ?

https://github.com/stackp/promisejs/tree/timeout

You can set the timeout value globally (in milliseconds) through the promise.timeout variable (e.g. promise.timeout = 3000;). The error code associated with a timeout is promise.ETIMEOUT:

promise.get('/').then(function(error, result) {
    if (error === promise.ETIMEOUT) {
        console.error("Timeout");
    }
});

Cheers

grobmeier commented 11 years ago

Thats great news! Yes, I will give it a test. It just takes me a while until I have some time to work on my mobile app again as I am currently busy with other things. I will come back to you as early as possible.

stackp commented 11 years ago

AJAX timeout was merged in bdecb2069bdbba, the option is now named promise.ajaxTimeout .