Ruslan Demyanov
12/30/2019, 11:03 AMval channel = ConflatedBroadcastChannel<String>()
launch {
listOf("1", "2", "3", "4", "5", "6").asFlow()
.onEach { Log.d("ORIGIN FLOW(onEach()):", it) }
.collect {
channel.offer("Channel: $it")
}
channel.asFlow()
.onEach {
Log.d("TEST FLOW(onEach()):", it)
}
.flatMapMerge { merge(flow1(), flow2()) }
.collect {
Log.d("TEST FLOW(collect()):", it)
}
}
bezrukov
12/30/2019, 11:18 AMcollect
is suspend fun, so you need to launch second coroutine for consuming channel.asFlow()bezrukov
12/30/2019, 11:19 AMRuslan Demyanov
12/30/2019, 11:45 AMbuffer
operator the channel will have time to receive only the first and the last element, is there any way that the whole chain will run on each item?bezrukov
12/30/2019, 11:48 AMBroadcastChannel
instead of ConflatedBroadcastChannel
. ConflatedBroadcastChannel
broadcasts only latest element.