Questions tagged [kotlin-flow]

In Kotlin coroutines, a Flow is a stream of asynchronously computed values. Use this tag when you're having problems building, transforming or consuming flows.

In Kotlin coroutines, a Flow is stream of asynchronously computed values.

Documentation: https://kotlinlang.org/docs/flow.html#flows

895 questions
0
votes
1 answer

kotlin - run sequentially flows

I have the following functions: fun validateEmail(email: String) = flowOf { when { email.isEmpty() -> throw EmailError.Empty email.contains("@") -> email else -> throw EmailError.NotValid } } fun…
Ricardo
  • 7,921
  • 14
  • 64
  • 111
0
votes
1 answer

Code from Coroutines callbackFlow is called only one time

I have function: @ExperimentalCoroutinesApi override suspend fun checkIsPostLiked(userId: String, postId: String): Flow = callbackFlow { try { …
pat20036
  • 83
  • 6
0
votes
1 answer

RxJava BehaviorSubject#onError(Throwable) equivalent in Kotlin Flow

I'm converting some RxJava code to Kotlin Flow in a project. I came across a piece of code where BehaviorSubject#onError(Throwable) was being called. I didn't find any way to do it with a Flow object. // RxJava val behaviorSubject =…
Augusto Carmo
  • 4,386
  • 2
  • 28
  • 61
0
votes
2 answers

Kotlin Flow still active in fragment after success

I've a fragment making a network request based on the result, I'm navigating to the next fragment. I am not able to go back to the previous fragment, this is the issue: https://streamable.com/4m2vzg This is the code in the previous fragment class…
0
votes
2 answers

How to pass result of livedata as a function argument using kotlin

How to use a livedata as an argument for another function? Every time I get a null value, I guess the function is called before the livedata can return hence the null value. I'm not using it from a View. I'm using it from the viewmodel, the function…
Dr4ke the b4dass
  • 1,184
  • 2
  • 17
  • 40
0
votes
2 answers

Flow provides null as data from room database

When I use Flow ( kotlinx.coroutines.flow.Flow) I get null as response. Dao code below : @Query("SELECT * FROM connect") fun getProfiles(): Flow> But when I use List and remove flow I get expected result. My…
Kamal Nayan
  • 1,635
  • 1
  • 5
  • 19
0
votes
0 answers

Combine multiple Kotlin flows with synchronous

I want to make 3 API calls. But 2 API calls must be asynchronous and the last one must be wait this results. And I want to write this in usecase so there is no viewmodelscope. I tried to write with zip but it can only create 2 API calls. class…
6155031
  • 4,171
  • 6
  • 27
  • 56
0
votes
2 answers

How to skip a Flow and just send last emitted value

I am working on a web application to visualize maze generation and solving algorithms based on Websockets. The generation algorithms implement the interface IMazeGenerator and return a Flow. interface IMazeGenerator { fun generate(maze: Maze):…
tihmels
  • 11
  • 1
  • 2
0
votes
1 answer

How to use flow binding

I try to handle clicks on my buttons and send action to viewModel private fun subscribeUI() { lifecycleScope.launch { binding.loginButton .clicks() .onEach { } .map {…
Wafi_ck
  • 1,045
  • 17
  • 41
0
votes
1 answer

How to chain APIs in Android to retrieve all pages from server using retrofit, flow, NetworkBoundResource inside repository class?

I am working on an Android App, which needs to retrieve all the pages from network to show details on screen. This is Youtube API https://developers.google.com/youtube/v3/docs/playlistItems/list Each response has nextPageToken, which needs to use…
Annada
  • 1,075
  • 1
  • 18
  • 21
0
votes
1 answer

Android LiveData - Object value is not updated

I use Kotlin Flow and LiveData to fetch objects from room database. I want to know that the value of the object in the database has changed. I did the following; UserDao @Query("SELECT * FROM user WHERE id=:userId") fun getUserById(userId: String?)…
Pehr Sibusiso
  • 862
  • 1
  • 14
  • 27
0
votes
1 answer

How do you emit multiple flow values as an object at the repository level?

Say I have two flows: val x: Flow = dao.getValueX() val y: Flow = dao.getValueY() Can I have a third flow, flow z which will emit these two as a pair? Say I have XYObject() where XYObject looks like X: Long? Y: Long? I want to…
0
votes
1 answer

When kotlin flow issues duplicate data 3 times, why does it only receive 2 times in collection?

I ran a basic test on the collect function to learn kotlin flow. There was something strange during the test, so I left a post In the flow block, there is a case where 3 identical emit values are entered. Then, the collected data was output to the…
Peter Y
  • 1
  • 1
  • 1
0
votes
1 answer

How do I properly use Flow.onStart {} to re-fetch cached content?

I have a method for fetching Something, let's make it a String for simplicity. The method should return a flow that initially emits the cached string, and then emits the “fresh” value after querying my API. Thankfully Room emits new data whenever a…
cekrem
  • 58
  • 1
  • 5
0
votes
0 answers

Coroutines in nested scopes

I'm writing an Android library and I have a situation (VERY simplified here for example's sake) with an interface where I need to make a function suspended to be able to call Flow.collect into it. interface Executor { suspend fun
kioli
  • 635
  • 1
  • 10
  • 26