dimsuz
01/09/2022, 7:09 PMval externalFlow = flowOf(1,3,4)
val myFlow = flow<Int> {
coroutineScope { externalFlow.collect { this@flow.emit(it + 8) } }
emit(1)
emit(99)
}
I've used coroutineScope, but I'm worried that it won't be cancelled when myFlow collection is cancelled or interrupted.
It's just that I've found internal flowScope builder in coroutines.core and it says:
This builder is similar to coroutineScope with the only exception that it ties lifecycle of children and itself regarding the cancellation, thus being cancelled when one of the children becomes cancelled.
Can I achieve similar effect for my case? Or using coroutineScope like I did is ok?dimsuz
01/09/2022, 7:21 PMexternalFlow finishes emissions 😞
I want something with the semantics: collect external flow just in case it will emit something, then emit this too, otherwise just emit my own stuff.dimsuz
01/09/2022, 7:36 PMmerge instead of collecting external flow inside flow {}Joffrey
01/09/2022, 8:11 PMchannelFlow builder, which allows you to start coroutines inside and send to the flow's channel concurrentlydimsuz
01/09/2022, 8:14 PM