In my endeavor to incorporate a simple timeout feature into my promise, I set out with the intention that if I do not receive a response within 1 second, the request should be terminated. The code should not hang for a response nor execute any code intended for success. Despite its apparent simplicity, this code is failing to function as expected. Here's what I have:
var canceler = $q.defer();
var timeoutPromise = $timeout(function() {
canceler.resolve(); //abort the request when timed out
console.log("Timed out");
}, 1000);
$http.put(PutUrl, PurDataObject, {timeout: canceler.promise})
.then(function(response){
// this section should never be reached if the response exceeds 1 second
});
Any assistance on this matter would be highly valued. My AngularJS version is 1.5.5.