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

Support for CancellationToken's #88

Closed
clairernovotny opened this issue Dec 11, 2014 · 11 comments
Closed

Support for CancellationToken's #88

clairernovotny opened this issue Dec 11, 2014 · 11 comments
Labels

Comments

@clairernovotny
Copy link
Member

If an interface method that supplies a CancellationToken, Refit should pass it to the underlying HttpClient call

@anaisbetts
Copy link
Member

Right now, cancellation is supported via the IObservable interface (i.e. unsubscribing early from Observable == cancel the call). I'm not suuuuuuper excited to try to cram it in as a magic parameter

@clairernovotny
Copy link
Member Author

WebAPI/MVC already does the magic parameter convention. If your web api method has a CancellationToken, it'll be populated so if the request dies, you can propagate it.

For people using the Task method, we need a way to abort it...

@mburbea
Copy link
Contributor

mburbea commented Apr 18, 2015

👍 On this. I currently workaround this by spawning a separate http client for each request, and binding the client's CancelPendingRequest method to the cancellationToken. It's ugly and inefficient, it'd be much nicer to just cancel the request I care about instead of all of them.

@MKuckert
Copy link

MKuckert commented Dec 2, 2015

Seems like this feature is implemented, right? I simply add a parameter of type CancellationToken to my method, or am I wrong?

@clairernovotny
Copy link
Member Author

Should be, yes.

@anaisbetts
Copy link
Member

We did it!

@michelmoorlag
Copy link

michelmoorlag commented Apr 26, 2017

I am a bit lost here. I am using Refit 2.4.1 in a Xamarin Forms project and I would like to be able to cancel http requests with a CancellationToken. So If I understand it correct I can add a CancellationToken parameter to the methods in the interface and then pass it in the implementation.

  1. Is my assumption correct?
  2. Is the location of the parameter important like first, last or?
  3. Does version 2.4.1 has this functionality, if not what version does?
  4. I am using a customHandler with a overridden SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) method. Will this cancellationToken be the one that is passed in the implementation?

A small example would be highly appreciated.

@michelmoorlag
Copy link

I just implemented it and based on that I can conclude the following:

  1. Yes
  2. Don't know, I have always put the token as first parameter and that seems to work
  3. Yes
  4. Yes
    Maybe somebody who knows more how refit works can confirm this?

@bennor
Copy link
Contributor

bennor commented Apr 27, 2017

Yes to all. Doesn't matter what the order of parameters is on your interface (they just get read out as a collection).

@michelmoorlag
Copy link

Thank you Bennor.
My app kicks off some requests in the background and in some situation like logout it is really handy to be able to cancel these requests with a cancellationtoken. This now works really well but documentation and samples on this issue are missing while this is quite important feature in my opinion.
If somebody is interested I can share some code how to use it in a CustomHandler.

@opcodewriter
Copy link

I'm having issues with this, if anybody could check it out I would appreciate some help: #339

@lock lock bot added the outdated label Jun 25, 2019
@lock lock bot locked and limited conversation to collaborators Jun 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants