pedroql / mvflow

Simple Android MVI architecture using Kotlin Flows
MIT License
124 stars 10 forks source link

How to stop an async task launched by the handler #38

Open BraisGabin opened 3 years ago

BraisGabin commented 3 years ago

I have a serch that each time that you type a character it launches a request. The problem is that if I don't cancel I could have this race condition:

At the end the user sees the results of "mv" instead of "mvf".

If I can cancel the collection of the current old flow I would fix it. Maybe there is other way to avoid this problem. I tried out this one: https://github.com/badoo/MVICore/issues/68#issuecomment-472109537 but Flow doesn't have a takeUntil.

BraisGabin commented 3 years ago

If someone see this. A workaround was posted in the last link of the previous post. Basically is an impelemntation of the operator takeUntil for Flow

pedroql commented 3 years ago

Hi,

This is indeed an interesting scenario (and I've needed this in other MVI libraries). I haven't had time to look into this so I don't yet know if it would be easy to plug this functionality or if it would require more significant changes. I'll try to have a look and post something, but I don't know when that will be possible.

Anyway, the source is relatively small so I would suggest you try it yourself. I'm happy to help too (within my time availability).