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

Rob

02/26/2021, 3:14 PM
Is there a way to use have a
MutableStateFlow<T : Any>
where the initial value is not set immediately? I am migrating from RxJava2
BehaviorSubject<T : Any>
. The value is not initialized until some process finishes. Observers of the value are transient. I would rather it not be a
T?
where I filter out the initial null value. Thanks!
t

Tijl

02/26/2021, 3:20 PM
SharedFlow
MutableSharedFlow
to be exact
r

Rob

02/26/2021, 3:21 PM
Does SharedFlow replay values for late observers?
t

Tijl

02/26/2021, 3:21 PM
yes
StateFlow extends SharedFlow in fact
r

Rob

02/26/2021, 3:24 PM
Interesting. StateFlow is similar to SharedFlow with replay of 1
t

Tijl

02/26/2021, 3:24 PM
yes, and conflated
😆 1
and with an initial value.
g

gildor

03/01/2021, 4:46 AM
is similar to SharedFlow
It’s not just similar, it is essentially SharedFlow with replace 1 (though both MutableSharedFlow and MutableStateFlow have some own features, but both based on AbstractSharedFlow implementation) https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/flow/StateFlow.kt#L76-L80
t

Tijl

03/01/2021, 10:07 AM
yes that comment just describes exactly what I said, replay 1, conflated, and with an initial value
1
2 Views