$http Timeout Promise: Resolution vs. Rejection Behavior
0 reputation · 06 Jan 2024, 01:42 UTC
AngularJS $http service supports a timeout configuration that accepts a promise. When the promise resolves, the pending HTTP request is aborted immediately. However, the framework’s response when the timeout promise is rejected remains ambiguous. Developers often use a $q.defer() promise as the timeout token, expecting that rejection would cancel the request, but the documented behavior does not explicitly state whether the request is aborted or allowed to complete to termination. This uncertainty affects cancellation strategies in component lifecycles and long-running applications where pending requests must be cleaned up upon scope destruction.
The core question is whether rejecting the timeout promise should be treated as a cancellation signal or simply ignored by the HTTP layer. Does rejecting the timeout promise cancel the $http request, or is the request permitted to finish normally? What is the intended design rationale for this behavior? What is the recommended pattern for reliably cancelling $http requests when a component or scope is destroyed?