-
Notifications
You must be signed in to change notification settings - Fork 931
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
How to auto cancel UseCase job when the ViewModel is destroyed #118
Comments
I feel that this code is redundant. You can make use of the |
Yes, we can make use of |
If you are accessing the use case from an Activity then, you are not adhering to |
Yes, I completely agree with you. |
I want to auto cancel all UseCase request that is tied to the ViewModel.
For now: I have reigstered a callback for
ViewModel.onCleared()
event. So when theonCleared()
is called, the callback will be invoked.For UseCase: I have defined two more functions,
cancelJob()
andmonitorViewModelLifecycle(vm: BaseViewModel)
and added another overloading functioninvoke(vm: BaseViewModel,params: Params,onResult: (Either<Failure, Type>) -> Unit = {})
.So, When the
ViewModel.onClearedListener
is invoked I'm cancelling the current Job.Is there any better to way to acheive this?
The text was updated successfully, but these errors were encountered: