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 }
}
}
}
Mikolaj Leszczynski
04/29/2021, 1:50 PMMikolaj Leszczynski
04/29/2021, 1:50 PMreduce
in intent
I don’t thinkMikolaj Leszczynski
04/29/2021, 1:51 PMflowOn
. Mainly you need to make sure that you’re collecting the flow on another dispatcherMikolaj Leszczynski
04/29/2021, 2:02 PMMikolaj Leszczynski
04/29/2021, 2:03 PMOleksii 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 PMMikolaj Leszczynski
04/29/2021, 5:51 PMOleksii Malovanyi
04/29/2021, 5:53 PMOleksii Malovanyi
04/29/2021, 5:54 PMOleksii Malovanyi
04/29/2021, 5:57 PMMikolaj Leszczynski
04/29/2021, 6:16 PMMikolaj Leszczynski
04/29/2021, 6:21 PMMikolaj Leszczynski
04/29/2021, 6:30 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 PMMikolaj Leszczynski
04/29/2021, 6:36 PMMikolaj Leszczynski
04/29/2021, 6:36 PMOleksii Malovanyi
04/29/2021, 6:37 PMMikolaj Leszczynski
04/29/2021, 6:40 PMMikolaj Leszczynski
04/29/2021, 6:41 PMMikolaj Leszczynski
04/29/2021, 10:58 PMMikolaj Leszczynski
04/29/2021, 11:04 PMMikolaj Leszczynski
04/30/2021, 5:59 AMOleksii Malovanyi
04/30/2021, 6:03 AMMikolaj Leszczynski
04/30/2021, 6:41 AMMikolaj Leszczynski
04/30/2021, 6:41 AMMikolaj Leszczynski
04/30/2021, 6:43 AMmiqbaldc
04/30/2021, 7:48 AMMikolaj Leszczynski
04/30/2021, 8:13 AM