https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

Tolriq

06/24/2023, 11:14 AM
Is there a proper way to have the following code
Copy code
combine(flow1,flow2) { slowJob() }.statein()
Have the slowjob cancelled when one of the source flow emit again?
j

Joffrey

06/24/2023, 11:20 AM
I haven't used
combine
in a long time, but isn't it by default how it works? Is
slowJob()
cancellable?
t

Tolriq

06/24/2023, 11:23 AM
It's not for now, but I still all all the results in the state if there was cancellation even just at the end it should not reach the state. With that said I'll try with adding explicit cancellation support as a first step.
So no there's no cancellation by default.
k

kevin.cianfarini

06/24/2023, 11:40 AM
Copy code
combine(flow1, flow2, ::Pair).mapLatest { (a, b) -> slowJob(a, b) }.stateIn()
t

Tolriq

06/24/2023, 1:17 PM
thanks that seems to work.