https://kotlinlang.org logo
Title
a

Adrian Blanco

10/29/2020, 9:19 AM
I recently migrated from
PublishSubject.create<T>()
to
MutableSharedFlow<T>(replay = 0, extraBufferCapacity = 1)
, but what I can't wrap my head around is what is the use case for
MutableSharedFlow<T>()
? (both parameters set to zero by default). It doesn't really seem to do anything.
g

gildor

10/29/2020, 9:23 AM
MutableStateFlow is like BehaviourSubject, so it replay = 1 and onBufferOverflow = DROP_OLDEST
+ it always has default value (which is not true for BehaviourSubject)
a

Adrian Blanco

10/29/2020, 9:24 AM
Ah sorry, meant default constructor for MutableSharedFlow 😅
g

gildor

10/29/2020, 9:25 AM
It doesn’t really seem to do anything
Isn’t it emit if it already have subscribers? I didn’t try, just asking Also default constructor uses Suspend overflow policty, so emitter will suspend in this case
a

Adrian Blanco

10/29/2020, 9:36 AM
I tried it very shortly and it seemed like it didn't emit to existing subscribers until I added the extra buffer capacity. But I was using tryEmit to post values instead of the suspending emit
g

gildor

10/29/2020, 9:38 AM
. But I was using tryEmit to post values instead of the suspending emit
Probably this why you have this problem, tryEmit will just drop value
There is no way to avoid suspension without buffer
a

Adrian Blanco

10/29/2020, 9:56 AM
Ah that makes a lot of sense, thanks :)