Oleksii Malovanyi
04/29/2021, 1:00 PMflow<Unit> {
while (true) {
delay(3000)
emit(Unit)
}
}.flowOn(<http://Dispatchers.IO|Dispatchers.IO>).onEach { _ ->
intent { reduce { it } }
}.launchIn(viewModelScope)
Unfortunately intent
coroutine couldn’t be used for this, as it would block all new messages from the RealContainer’s channel
intent {
flow<Unit> {
while (true) {
delay(3000)
emit(Unit)
}
}.flowOn(<http://Dispatchers.IO|Dispatchers.IO>).onEach { _ ->
intent { reduce { it } }
}.collect()
}
Mikolaj Leszczynski
04/29/2021, 1:49 PMintent {
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
flow<Unit> {
while (true) {
delay(3000)
emit(Unit)
}
}.collect {
reduce { it }
}
}
}
reduce
in intent
I don’t thinkflowOn
. Mainly you need to make sure that you’re collecting the flow on another dispatcherOleksii Malovanyi
04/29/2021, 5:19 PMRealContainer
still waits for collect
to finish (and it never finishes). I’ve tried to modify RealContainer
to receive channel’s messages as a flow in a separate coroutine, but the problem is reduce
state is in a race condition then 😞 I’ll try to play around it a bit and propose to move our conversation to github’s issue 🔝Mikolaj Leszczynski
04/29/2021, 5:39 PMOleksii Malovanyi
04/29/2021, 5:53 PMMikolaj Leszczynski
04/29/2021, 6:16 PMOleksii Malovanyi
04/29/2021, 6:34 PMlaunchIn
) to not to block the intent
with collect
But surely wouldn’t go with either if we still could make intent
work safely without blockingMikolaj Leszczynski
04/29/2021, 6:35 PMOleksii Malovanyi
04/29/2021, 6:37 PMMikolaj Leszczynski
04/29/2021, 6:40 PMOleksii Malovanyi
04/30/2021, 6:03 AMMikolaj Leszczynski
04/30/2021, 6:41 AMmiqbaldc
04/30/2021, 7:48 AMMikolaj Leszczynski
04/30/2021, 8:13 AM