-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Requests by $resource "class" actions can not be aborted #5612
Comments
Suggested labels: |
…"class" actions `$resource` "class" actions delegate to `$http` in a fashion that does not allow to pass timeout promise to individual requests. Hence these individual requests can not be cancelled. This patch adds $abort method to the object returned by `$resource` "class" actions. Closes angular#5612
Definitely in favor of this or something else that gets the job done! Has Any idea if something has been merged/if they've come up with something equivalent? |
We need a way to abort individual resource requests. A guy on the Rackspace blog developed some methods to make it possible and simple, but it seems wrong that he had to do all this to get this basic functionality. http://developer.rackspace.com/blog/cancelling-ajax-requests-in-angularjs-applications.html I need to abort requests if people click too fast on a pager. There are probably countless other times people will want this feature. |
That would be great. @BrianBarker I tried the implementation found on the Rackspace blog, but the abort() method doesn't seem to work. It looks like it only aborts the callback execution, not the request itself. Did you manage to actually abort some requests with it? |
Just a note about the current state of affairs: canceling promises is hard (not properly solved) problem in the promise community in general (outside of angular) because it breaks several guarantees promises give you and makes composition hard. This is why we don't have a straightforward api. The timeout solution is a nifty hack that one of our community members came up with. There are long discussion about this on several issues in our issue tracker. |
I assume this has benn fixed by 98528be |
After accepting PR #2529 ("add support for timeout promises") the
timeout
parameter for$http
can be a promise, and resolving it will abort the request.$resource
passesactions
to$http
so one can also passtimeout
promise.However if I initialize a
$resource
object to use it for multiple "class" actions requests, I can specifytimeout
only once — at the moment of initialization. All the requests made by this object will share the same timeout promise, so effectively only one of them can be aborted.So far I am planning to write a patch to add
$abort()
method to the object returned by "class" actions requests of$resource
. However even at this stage the resulting mix of APIs does not seem nice. (Neither does cancelling via timeout promise, by the way.)I imagine that cancelling API should be the same for
$http
requests and$resource
requests. Passing an object as a parameter to be able to abort the request does not seem right. Given how$resource
is used,$abort
method belongs to the object returned by$resource
"class" actions calls. However instance call returns promise, and we cannot reject it. Should the aborting API be different for instance and non-instance calls?Your ideas on the best approach to that problem are welcome!
The text was updated successfully, but these errors were encountered: