forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($resource): add support for cancelling requests using promises
Previously, it was not possible to use a promise as value for the `timeout` property of an action's `config`, because that value would be copied before being passed to `$http`. This commit introduces a special value for the `timeout`, namely `'promise'`. Setting an action's `timeout` configuration property to `'promise'`, will create a new promise and pass it to `$http` for each request. The associated deferred, is attached to the resource instance, under `$timeoutDeferred`. Example usage: ```js var Post = $resource('/posts/:id', {id: '@id'}, { query: { method: 'GET', isArray: true, timeout: 'promise' } }); var posts = Post.query(); // GET /posts ... // Later we decide to cancel the request // in order to make a new one posts.$timeoutDeferred.resolve(); posts.query({author: 'me'}); // GET /posts?author=me ... ``` Fixes angular#9332 Closes angular#13050
- Loading branch information
Showing
2 changed files
with
153 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters