Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel a request #1377

Closed
clementbirkle opened this issue May 26, 2016 · 2 comments
Closed

Cancel a request #1377

clementbirkle opened this issue May 26, 2016 · 2 comments

Comments

@clementbirkle
Copy link

To avoid duplication of requests (double click), I would be able to stop a running query. I do not see how. Can you help me please ?

let inProcess = false;

return Restangular.withConfig(function(RestangularConfigurer) {
    RestangularConfigurer

        ...

        .addFullRequestInterceptor(function(element, operation, what, url, headers) {

            if (inProcess) {
                // cancel the request here
                return;
            }

            inProcess = true;

        })

        ...
});
@daviesgeek
Copy link
Collaborator

Here's the way I've done it:

let canceler = $q.defer()
Restangular.all('users').withHttpConfig({timeout: canceler.promise}).get()
canceler.resolve() // cancels the request

This is a little counterintuitive, so let me explain. $http takes a timeout parameter (see the $http docs:

timeout in milliseconds, or promise that should abort the request when resolved.

Resolving the promise (canceler in this case), will cancel the request

@clementbirkle
Copy link
Author

Really great ! It works well, thank you for your solution :)

bostrom added a commit that referenced this issue Dec 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants