https://kotlinlang.org logo
Title
a

Archie

03/02/2021, 2:53 AM
Hi, I was wondering how to cancel a request in MVI? Lets say an intent starts a network request but another intent must cancel it?
a

Arkadii Ivanov

03/02/2021, 9:46 AM
Hi, there are multiple ways. 1. A better way would be to store a Disposable/Job in the State. 2. Or you can store it directly in the Executor's private property. There are cases when you need to cancel previously running task before starting a new one. In this case I usually have a private property with
PublishSubject<Unit>
. And for each task I first do
subject.onNext(Unit)
, and then
myNewTask.takeUntil(subject)
.
❤️ 1