RestClient
RestClient copied to clipboard
Promise abort enhancement
Iv been using the library for last few weeks and it has worked for me very well, however there is one thing that I find abit inconvenient - aborting requests.
I set up a repository class for my rest api:
public class LadderRepository : MonoBehaviour {
private static string ladderFinalUrl = "ladder";
private readonly IList<RequestHelper> requests = new List<RequestHelper>();
private void Awake() {
InitUrls();
}
private void InitUrls() {
.....
}
public IPromise<LadderResponse> FetchLadder() {
var requestHelper = ComposeRequest(ladderFinalUrl);
return RestClient.Get<LadderResponse>(requestHelper);
}
}
Basically I expose IPromises
for other game objects that want to communicate with the api, now my problem is aborting individual IPromises
.
Ideally Id like to just call a method Abort
on given IPromise
to cancel given api call. I am used to abort things like this from rxjava - disposing an observable whenever I feel like.
Maybe I am missing something but right now Id have to expose given RequestHelpers
to achieve what I want, which doesnt seem to be so clean. What do you think about it?
You can have a loop to iterate your requests
list in order to call the Abort
method of every request of the RequestHelper
object, what you think?
Yes thats true, actually that is what I am doing at the moment. But still that has its own limitations - maybe I want to abort only some of the requests or only one particular request.
That could be also solved, yes - for example by having a Dictionary<int, RequestHelper>
- where key would be promise id and value its respective request helper - then Id abort individual requests with given id.
Still not as convenient as simply calling IPromise.Abort()
without anything else.
ohh it would be awesome, any pull request is welcome! 💯
If #226 gets merged, ProtoPromise comes with CancelationToken
that can have aborts registered to it.