why it changes whether use ShareIn func or not
val sharedf = MutableSharedFlow<Int>()
fun Flow<Int>.print() : Flow<Int> {
return map {
println("in print : $it")
it
}
}
fun Flow<String>.printS() : Flow<Int> {
return map {
println("in print : $it")
it.toInt()
}
}
fun Flow<Int>.toNext() : Flow<Int> {
return merge(
filterIsInstance<Int>().print(),
filterIsInstance<String>().printS(),
)
}
when I use main func like this
fun main() = runBlocking<Unit> {
launch {
sharedf.onSubscription{
println("subsCount : ${sharedf.subscriptionCount.value}")
}
.shareIn(GlobalScope, SharingStarted.Lazily)
.toNext()
.collect()
}
launch {
for (i in 0..3){
delay(500)
sharedf.emit(i)
}
}
}
subsCount : 1
but if I remove ShareIn
subsCount : 2
why I have to Use ShareIn even sharedf is already MutableSharedFlow