All Questions
Tagged with kotlin-flow reactive-programming
12 questions
1
vote
2
answers
2k
views
How we can collect flows from another collect or nested flow?
I am getting Flow of records (Flow<List<Record>) from Dao, now on the basis of these records I have to fetch another list of flows (Flow<List<AnotherRecord>>) , but collect ...
0
votes
1
answer
224
views
How to react to changes in two tables with Kotlin Flow and Android Room database
I have two simple tables.
ProductId
Brand
Name
Description
1
...
...
...
2
...
...
...
3
...
...
...
ProductId
Favourite
ShoppingList
1
false
true
3
true
false
The first table stores the data ...
0
votes
0
answers
590
views
Kotlin flow replay
Is there a way I can 'replay' the last emitted value for a certain subscriber instead of setting 'replay' to the producer?
I just want only a certain subscriber to get the replayed value and not the ...
1
vote
1
answer
489
views
Combine Kotlin Unit flows without transform function
I have currently two SharedFlows that I need to combine to do something, but I don't really need the result from the transformation function, I only want to know if both "events" started yet....
0
votes
1
answer
1k
views
How can I get a previous emission Kotlin Flow?
Let me use a simple image to illustrate what I want to get:
I don't want to use SharedFlow's replayCache to achieve this because if a new observer observes that SharedFlow, it will get 2 emissions ...
2
votes
0
answers
1k
views
Why is tryEmit not included in the FlowCollector interface?
MutableSharedFlow and MutableStateFlow (via inheritance) include both the emit suspend function and the best effort, non-suspend tryEmit. But FlowCollector only includes emit in the interface. It ...
4
votes
2
answers
8k
views
Flow wait some time, then gather all emitted elements into a list, and keep this process running
I have a flow producer that will emit elements with random period, I don't want to handle these elements once it emit, I'd rather gather them into a list, then handle them, and keep this process ...
3
votes
1
answer
2k
views
How to combine results from a suspend function and a flow in kotlin?
Guys imagine I have these two sources of data:
val flowA: Flow<String>
suspend fun funB(): Int
How can I combine the result of both into a flow (let's say Flow<Pair<String, Int>>)?
...
1
vote
1
answer
2k
views
How to chain API requests using Kotlin Flow
Based on a list of ids I need to retrieve a list of users with detailed informaiton of each user. Below a simplification of my models and API;
data class UserDTO(val id: String)
data class PetDTO(val ...
1
vote
1
answer
876
views
How can I consume the results of two coroutines returning two different Result types?
Coroutine 1 returns Result<A>;
Coroutine 2 returns Result<B>;
Both results need to map to some kind of UI format, e.g. MenuItem;
If coroutine 1 fails, the process should terminate and ...
14
votes
3
answers
15k
views
Kotlin Flow execute two API calls in parallel and collect each result as it arrives
I am trying to implement cache then network strategy for my API call using Kotlin Flows.
Here is what I am trying right now
flowOf(
remoteDataSource.getDataFromCache() // suspending function ...
4
votes
1
answer
5k
views
How to stop Kotlin flow when certain condition occurs
I want to cancel kotlin flow if certain condition occurred in code.
Suppose i have a method as following
fun test(): Flow<String> = flow {
val lst = listOf("A", "B", "C")
while(true) {...