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

How to write unit test for Flows in Kotlin multiplatform

Hi I am trying to write some unit test cases for the Stateflow and Flow in Kotlin Multiplatform, My requirement is val loader = MutableStateFlow(false) suspend fun fetchBugs(bugsParams: BugsApiRequestParams) { val responseObject =…
0
votes
1 answer

Combining kotlin flow results

I'm wandering if there is a clean way to launch a series of flows in Kotlin and then, after their resolution, perform further operations based on whether they succeeded or not For example's sake I need to read all integers from a DB (returning them…
kioli
  • 635
  • 1
  • 10
  • 26
0
votes
2 answers

Update (or create) flow inside itself and emit this, Room, Flow, MVVM

I have been creating an SMS app. I have a list of conversations stored in Room database as ConversationEntity. This is my query: @Query("SELECT * FROM conversation_entity ORDER BY timestamp DESC") fun getAllConversations():…
rogalz
  • 80
  • 8
0
votes
1 answer

unit testing repository that use flow coroutine kotlin in android

I want to write unit test for my repository. The repository's methods return flow. The addDiaryRate method first of all emit loading state then return data from network. I want to verify that addDiaryRate method emit loading then data response. I…
maryam
  • 1,437
  • 2
  • 18
  • 40
0
votes
1 answer

Kotlin: CoroutineScope is collecting data even after flow is cancelled

I am trying to launch an Coroutine inside my PagingSource in order to watch how long my paging source is already trying to get my data. The only problem I have here is, that my Coroutine is still somehow collecting some data, even after I stopped my…
Andrew
  • 4,264
  • 1
  • 21
  • 65
0
votes
2 answers

How to return callback/stream to the caller thread?

I have some class 'A', the internal work of which is performed using rx or coroutines with flows. Class 'A' should not return any instances of rx/coroutines (and flows), their work should be hidden, we need Future result for callbacks and observe on…
Mark D
  • 95
  • 2
  • 8
0
votes
1 answer

Kotlin Flow, make flow conditional - only make call if true

Just starting to work with Kotlin flows. I basically only want to insert an item into a room database if the record is unique. I thought I could probably do this with @Insert(onConflict = OnConflictStrategy.REPLACE) but imageUrl will always be…
aidanmack
  • 518
  • 1
  • 5
  • 16
0
votes
1 answer

Kotlin coroutines Flow is not canceled

I have a UseCase class with method that returns Flow fun startTimeTicker(startTime: Long) = flow { val countdownStart = System.currentTimeMillis() for (currentTime in countdownStart..startTime step ONE_SECOND_MILLIS) { ....…
0
votes
1 answer

How can I provide a 'close reason' for a Flow without using exceptions?

Say I'm producing a finite stream of messages as a Flow. I loop over some source of messages, and, when there are no more messages, break out of the loop to finish the flow normally. val messages = flow { while (source.hasNext()) { …
Sam
  • 8,330
  • 2
  • 26
  • 51
0
votes
1 answer

Kotlin flow: Weird behavior, code executed 3 times while it is supposed to be executed only once

I start recently studying a project which uses kotlin flow + coroutine and I found a weird thing, I write some code to reproduce the issue, here is the code import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import…
陈建伟
  • 1
  • 3
0
votes
1 answer

How to write an extension function / wrapper for Kotlin Coroutines Flow?

I have Coroutines code which is using a callbackFlow like this: fun getUniqueEventAsFlow(receiverId: String): Flow = callbackFlow { RxEventBus().register( receiverId, FirstUniqueEvent::class.java, false ) {…
IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
0
votes
1 answer

PagingDataAdapter.submitData not adding data

I'm using Paging 3 from the jetpack libraries, after inserting a data to room db, collectLatest gets called but after adding data with PagingDataAdapter.submitData, it doesn't seem to add to the adapter. I tried using adapter.refresh and…
0
votes
1 answer

Implement backoff strategy in flow

I'm trying to implement a backoff strategy just using kotlin flow. I need to fetch data from timeA to timeB result = dataBetween(timeA - timeB) if the result is empty then I want to increase the end time window using exponential backoff result =…
ImMathan
  • 3,911
  • 4
  • 29
  • 45
0
votes
1 answer

How to create a flow with a few subscribtions in Kotlin?

I need to run a task, which emits some data. I want to subscribe to this data like PublishSubject. But I can't solve a problem of one-instance flow. If I try to call it again, it will create another instance and the job will be done twice. I tried…
VolodymyrH
  • 1,927
  • 2
  • 18
  • 47
0
votes
1 answer

Kotlin Flow On Android: Launch and Merge subflows from Parent

im loading a Flow> from the database. Based on this result i want to transform each element a with another database call to a Pair. So basically this: dao.getElementAList().map { list -> list.map {elementA -> Pair(it,dao.call2(elementA)) } } The…
Ditscheridou
  • 381
  • 1
  • 5
  • 18
1 2 3
59
60