alexsullivan114
04/02/2020, 7:20 PMChannel
that I'm converting to a flow and listening to. As soon as the channel is created I'm sending through an initial default value. Right before that happens I'm observing the flow
using the onEach pattern. The flow, however, is not receiving the initial value, presumably because there's an asynchronous launch involved. Does anyone have any idea how to get around this issue?octylFractal
04/02/2020, 7:22 PMonEach
observes the flow at all? are you eventually calling a terminal op like launchIn
or collect
?alexsullivan114
04/02/2020, 7:22 PMlaunchIn
octylFractal
04/02/2020, 7:23 PMalexsullivan114
04/02/2020, 7:23 PMobject Woofers {
fun doStuff(scope: CoroutineScope) {
val channel = BroadcastChannel<Int>(Channel.BUFFERED)
channel
.asFlow()
.onEach { println("Value: $it") }
.launchIn(scope)
// Won't be received
channel.offer(1)
}
}
octylFractal
04/02/2020, 7:38 PMflow.onStart { emit(1) }
might be a better solutionstreetsofboston
04/02/2020, 9:56 PMalexsullivan114
04/04/2020, 3:34 PM