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
Adds the possibility to cancel all callbacks of a promise #50
Conversation
…t leak classes when leaving the app and those callbacks are no more needed.
hiya - which version of jdeferred are you using? the latest should've been patched where finished promises would've cleared all the callbacks. |
The case what I see we need this is when the Promise is not already finish |
I would 👍 the request for a cancel() method on a promise. However, this changeset does not seem complete, as ideally the creator of a deferred object would be able to register on cancel and do something. As an example, consider having a promise for an API Http request. Ideally, you would like to be able to cancel the request as well. |
agreed - I do feel we can implement cancel if and only if the underlying task is also cancelable. But, a promise is also immutable. What do you feel about making Deferred object cancelable? |
Hi everyone, how is this going on? I'm waiting for it to be merged :) |
hi @raycoarana! just getting back to this, I'm thinking of renaming the method to something else. p.cancel() feels like we are canceling the promise/task, rather than cleaning up the handlers/callbacks. Would you be able to suggest another name? |
Sure, maybe clearCallbacks() is clear enough. What do you think? |
/cc @aalmiray we don't have ways to clear callbacks. But, having |
it looks to me that the actual problem is that the task may still be running, not the fact that the promise has at least one callback registered. If this is the case then we must find a way to cancel tasks submitted via |
This method try to help apps developers that wan't to prevent leaks of Activity/Fragment when a user is leaving them and a promise is pending to be completed. Removing all callbacks let the Activity/Fragment to be garbage collected.
This change is