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

Promise abort enhancement #107

Open
cetonek opened this issue Dec 5, 2019 · 4 comments
Open

Promise abort enhancement #107

cetonek opened this issue Dec 5, 2019 · 4 comments

Comments

@cetonek
Copy link

cetonek commented Dec 5, 2019

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?

@jdnichollsc
Copy link
Member

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?

@cetonek
Copy link
Author

cetonek commented Dec 6, 2019

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.

@jdnichollsc
Copy link
Member

ohh it would be awesome, any pull request is welcome! 💯

@timcassell
Copy link

If #226 gets merged, ProtoPromise comes with CancelationToken that can have aborts registered to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants