bloder
06/12/2019, 12:12 PMConflatedBroadcastChannel, this is what I want:
val conflated = ConflatedBroadcastChannel<Int>()
val stringConflated: ConflatedBroadcastChannel<String>() = conflated.toStringConflated()
launch {
stringConflated.consumeEach { println(it) }
}
launch {
conflated.send(2) // will print "2" (as string)
}
I've tried some approachs to toStringConflated such as:
suspend fun ConflatedBroadcastChannel<Int>.toStringConflated(): ConflatedBroadcastChannel<String> =
ConflatedBroadcastChannel<String>().apply {
this@toConflatedString.consumeEach { // map value here }
}
But when I apply a consumerEach to my ConflatedBroadcastChannel<Int> my ConflatedBroadcastChannel<String>() stops to consume values, is there a way to do what I'm trying?bloder
06/12/2019, 12:40 PMsuspend fun CoroutineScope.mappableConflated(conflated: ConflatedBroadcastChannel<Int>): ConflatedBroadcastChannel<String> =
ConflatedBroadcastChannel<String>().apply {
launch {
conflated.consumeEach {
this@apply.send(it.toString())
}
}
}bdawg.io
06/12/2019, 8:51 PMconsumeEach was causing your code to suspend before stringConflated was actually assigned