Make it possible to cancel a running use case in todo-mvp-clean
UseCaseHandler.execute() needs to return an object that lets us cancel an ongoing task. This is to prevent the callback from leaking a reference to the view. The cancel operation doesn't need to abort the thread, but should basically clear the reference to the callback to avoid the leak. See #154
I solved that by returning a Subscription(direct copy from RxJava) which UseCase implements. e.g.,
Subscription subscription = UseCaseHandler.execute(doFoo, ...);
~~where UseCaseHandler.execute() returns UseCase itself internally.~~ Don't do that this leaks callback reference
I've reviewed the code and we are leaking the callback reference, my fault. I don't like to create a cancel method for avoiding this one because is move the decision to the developer and it's easy to forget it. My idea is to take weak references and not a strong reference for the callback, this will and auto cancel for those calls that don't have a callback attached.
I will add a pull request during this weekend.
@flipper83 isn't it risky to trust object to be garbage collected from memory to unsubscribe from callbacks? and most likely leak-prune
Yeah, have to agree with @gokhanbarisaker. A weak reference is not very optimal. We already have subscribe/unsubscribe in other samples, so it should be fine to use that here as well. The view tells the presenter when it is being detached.
Closing as obsolete in the context of the current architecture guide.