Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
209 views

I am testing a ViewModel using a fake repository which uses a StateFlow to store the fake data. This StateFlow is exposed as a normal Flow from the repository. In the ViewModel, I am mapping the ...
Kahan Bhalani's user avatar
1 vote
1 answer
275 views

I investigated for hours and searched the web (and even bothered ChatGPT) and I'm puzzled this hasn't been solved yet to my (obviously very limited) knowledge. So this is the setup: I have a view ...
nepa's user avatar
  • 1,472
2 votes
0 answers
330 views

example code: suspend fun main() { val start = System.currentTimeMillis() flowOf("flow value") // 1 .onStart { println("onStart delta: ${System.currentTimeMillis() - ...
鱼呀鱼呀鱼子酱's user avatar
2 votes
1 answer
544 views

I was trying Kotlin coroutines using a test file. What I observed is that the async{..} block , completes and then the next async block starts. @Test fun `xyz`() { runBlocking { val x = ...
Makruzz's user avatar
  • 127
0 votes
1 answer
171 views

I'm struggling to understand why this is so difficult to figure out. This is in Android if it matters. Please see the code below private val _myFlow = MutableStateFlow<Result<Flow<...
Ali Kazi's user avatar
  • 1,667
0 votes
1 answer
828 views

With Kotlin Coroutines I need to run two I/O work inside a try block at same time parallely without blocking each other. And if any of the work fails, then it should be caught inside a single catch ...
SVK's user avatar
  • 776
0 votes
1 answer
248 views

There is code sample: fun main() { runBlocking { val sourceFlow = MutableSharedFlow<Int>() val mappedFlow = sourceFlow .map { println("...
Puzirki's user avatar
  • 452
2 votes
1 answer
1k views

There is the sourceFlow and I use flatMapLatest to produce new flow by value from sourceFlow. And there is no value in collect(). This code prints nothing. fun main() { fun createNewFlow(): ...
Puzirki's user avatar
  • 452
0 votes
1 answer
502 views

I have the following that returns a Flow<List<Events>>. But I want return the List<Events>> from the flow instead of Flow<List> val events = eventDao.getEventsFromTimeStamp(...
ant2009's user avatar
  • 22.7k
1 vote
1 answer
217 views

I'm playing with Paging3 with Room. I wrote a little test app that populates a Room DB with a single table with 5 string fields (plus its id). I populate the table with 100,000 items. The code for ...
johngray1965's user avatar
2 votes
1 answer
3k views

What I'm trying to achieve is that flowB is just (re)subscribed when flowA emits a value different of null. But there is no standard way to do that (as I can see). In my scenario, flowB is expensive ...
Luan's user avatar
  • 166
1 vote
0 answers
590 views

I’m having some trouble to test some state changes in my viewModel using MutableSharedFlow. For example, I have this class class SampleViewModel : ViewModel() { private val interactions = Channel&...
Esdras's user avatar
  • 365
0 votes
0 answers
218 views

I am practicing Coroutines Channel and I'm wondering why does the repository.getAllRates() did not trigger even my code reached the sellCurrencyChannel.send(CurrencyRate(“”, 0.0))? I'm also suspecting ...
HellBoy's user avatar
1 vote
1 answer
2k views

I am struggling test and/or implement a method that listens to an infinite flow in the background. Specifically, the use case I have in mind is a repository for some data that has a local and remote ...
sjp's user avatar
  • 392
2 votes
2 answers
2k views

I want to use SQLDelight as a caching layer in my App with the coroutines extension to return a flow from my SQL queries and get notified when the entry in the local Database changes. But because ...
JonasLevin's user avatar
  • 2,157
1 vote
1 answer
2k views

I got this code right here, that works fine. I can print out the values i get from every job/coroutines that launches inside the scope. But the problem is that i struggle to use the values outside of ...
dogTheCode's user avatar
7 votes
1 answer
2k views

I am trying to create a moving window of data using Kotlin Flows. It can be achieved in RxKotlin using a buffer, but buffer is not the same using Flows. RxKotlin has a buffer operator, periodically ...
Sprout's user avatar
  • 640
4 votes
1 answer
1k views

I'm trying to follow this documentation here concerning how to unit test a PagingData stream on which you're applying transforms. The code I am using is similar: @ExperimentalCoroutinesApi @Test fun ...
J. Hill's user avatar
  • 545
3 votes
3 answers
6k views

I'm trying to create a flow with coroutines but it's not giving to me the expected result. What I'd like to have is giving an expiration time (doesn't matter if it's in millis, seconds, etc..) when ...
StuartDTO's user avatar
  • 1,091
1 vote
1 answer
6k views

I already added coroutine play services into my code, everything was working find, but after updating coroutines to the version 1.3.2, my application crash and give me the error bellow, but into the ...
Tsafack Dagha cedrick's user avatar
1 vote
1 answer
6k views

I have collect flow from shared viewmodel in fragment : private val viewModel: MyViewModel by sharedViewModel() private fun observeViewModelStateFlowData() { job = lifecycleScope.launch { ...
MeNoVa's user avatar
  • 99
3 votes
1 answer
4k views

We have a Rest Service that returns a text/event-stream from a POST endpoint, which contains a series of JSON Objects. (It is a Spring Boot / Kotlin RestController that returns a kotlinx.coroutines....
epikmartin's user avatar
4 votes
2 answers
6k views

I've one LiveData named sortOrder and then I've another variable named myData that observes any change to sortOrder and populates data accordingly. class TestViewModel @ViewModelInject constructor() : ...
theapache64's user avatar
  • 11.8k
4 votes
2 answers
2k views

Let's make this simple. I've one MutableSharedFlow named sortOrder in my ViewModel. private val sortOrder = MutableSharedFlow<String>( replay = 0, extraBufferCapacity = 1 ) I've a ...
theapache64's user avatar
  • 11.8k
4 votes
1 answer
2k views

What i am doing So i am developing a weather forecast application in which i am accessing the device location using fusedLocationProviderClient.lastLocation and most of us knows that the location ...
Saquib Siddique's user avatar
8 votes
2 answers
15k views

I'm trying to deliver realtime updates to my view with Kotlin Flows and Firebase. This is how I collect my realtime data from my ViewModel: class MainViewModel(repo: IRepo): ViewModel() { val ...
SNM's user avatar
  • 6,965
27 votes
3 answers
19k views

I notice a strange behavior when trying to prematurely cancel from a Flow. Take a look at the following example. This is a simple flow that emits integer values private fun createFlow() = flow { ...
ThanosFisherman's user avatar
17 votes
1 answer
16k views

I'm replacing my current implementation using RxJava to Coroutines and Flow. I'm having some trouble using some Flow operators. I'm trying to filter the list of items inside a Flow before providing ...
Igor Escodro's user avatar
  • 1,339
43 votes
3 answers
19k views

In the last Google I/O, Jose Alcerreca and Yigit Boyar told us that we should no longer use LiveData to fetch data. Now we should use suspend functions for one-shot fetches and use Kotlin's Flow to ...
Dmitry  Simakov's user avatar
15 votes
3 answers
6k views

I am trying to migrate from LiveData to Flow in my Room Dao. App is working fine, but I have problems with testing behavior. When I run the test it is starting and running indefinately. I also tried ...
OMIsie11's user avatar
  • 469
0 votes
0 answers
742 views

I am just starting to familiarize myself with Kotlin flows. For this, I am using them to parse the contents of a binary file which I will simulate using the following flow: fun testFlow() = flow { ...
Matthias's user avatar
  • 12.3k
42 votes
3 answers
28k views

I wanted to know how can I send/emit items to a Kotlin.Flow, so my use case is: In the consumer/ViewModel/Presenter I can subscribe with the collect function: fun observe() { coroutineScope.launch ...
Joaquim Ley's user avatar
  • 4,137