aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/httpBackend.js
diff options
context:
space:
mode:
authorDavid Bennett2013-04-27 11:22:03 -0400
committerIgor Minar2013-05-20 14:15:04 -0700
commit9f4f5937112655a9881d3281da8e72035bc8b180 (patch)
treef6c9b19448ea5ddde11198b0e6d7a516e0b83d7b /src/ng/httpBackend.js
parent27a8824b50aa78e9a082b4377ca09250382a8655 (diff)
downloadangular.js-9f4f5937112655a9881d3281da8e72035bc8b180.tar.bz2
feat($http): add support for aborting via timeout promises
If the timeout argument is a promise, abort the request when it is resolved. Implemented by adding support to $httpBackend service and $httpBackend mock service. This api can also be used to explicitly abort requests while keeping the communication between the deffered and promise unidirectional. Closes #1159
Diffstat (limited to 'src/ng/httpBackend.js')
-rw-r--r--src/ng/httpBackend.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js
index 69ac5976..ed8404f9 100644
--- a/src/ng/httpBackend.js
+++ b/src/ng/httpBackend.js
@@ -107,20 +107,25 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
}
if (timeout > 0) {
- var timeoutId = $browserDefer(function() {
- status = -1;
- jsonpDone && jsonpDone();
- xhr && xhr.abort();
- }, timeout);
+ var timeoutId = $browserDefer(timeoutRequest, timeout);
+ } else if (timeout && timeout.then) {
+ timeout.then(timeoutRequest);
}
+ function timeoutRequest() {
+ status = -1;
+ jsonpDone && jsonpDone();
+ xhr && xhr.abort();
+ }
+
function completeRequest(callback, status, response, headersString) {
// URL_MATCH is defined in src/service/location.js
var protocol = (url.match(SERVER_MATCH) || ['', locationProtocol])[1];
- // cancel timeout
+ // cancel timeout and subsequent timeout promise resolution
timeoutId && $browserDefer.cancel(timeoutId);
+ jsonpDone = xhr = null;
// fix status code for file protocol (it's always 0)
status = (protocol == 'file') ? (response ? 200 : 404) : status;