Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Requests by $resource "class" actions can not be aborted #5612

Closed
arty-name opened this issue Jan 3, 2014 · 6 comments
Closed

Requests by $resource "class" actions can not be aborted #5612

arty-name opened this issue Jan 3, 2014 · 6 comments

Comments

@arty-name
Copy link
Contributor

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 passes actions to $http so one can also pass timeout promise.

However if I initialize a $resource object to use it for multiple "class" actions requests, I can specify timeout 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!

@arty-name
Copy link
Contributor Author

Suggested labels:
type: feature
component: ngResource
PRs welcome!
impact: small
complexity: small
gh: issue
needs: public api

arty-name pushed a commit to arty-name/angular.js that referenced this issue Jan 3, 2014
…"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
@ghost ghost assigned tbosch Jan 4, 2014
@thynctank
Copy link
Contributor

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?

@ghost
Copy link

ghost commented Jun 30, 2014

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.

@pjparra
Copy link

pjparra commented Jul 16, 2014

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?

@IgorMinar
Copy link
Contributor

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.

@btford btford removed the gh: issue label Aug 20, 2014
@Narretz
Copy link
Contributor

Narretz commented Feb 13, 2017

I assume this has benn fixed by 98528be

@Narretz Narretz closed this as completed Feb 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.