Questions tagged [kotlin-sharedflow]

52 questions
0
votes
0 answers

A bug about kotlin SharedFlow

I created a SharedFlow, and first I added a Collector to it. Then six coroutines were started to emit data inside. Delay for a certain amount of time to ensure that the data has been emitted. cancel some coroutines. Then added a new collector. fun…
kkk
  • 141
  • 5
0
votes
1 answer

android kotlin Flow emitted values are not collected

I have model class: data class TweetResponse( val data: Data?, val matching_rules: List?, val lifeSpan: MutableStateFlow? = MutableStateFlow(30), var timer: CountDownTimer? ) In my repository class I get list…
Kratos
  • 681
  • 1
  • 13
  • 30
0
votes
1 answer

Kotlin Coroutines - Unit tests with SharedFlow falls when run together but pass when run individually

I am trying to write class which will get some current data every some time so it will transform one flow into another. I go stuck while writing tests for it. When I run one test it passes but when I run all of them: testA always passes but testB or…
0
votes
1 answer

Retrigger collection from StateFlow/SharedFlow from Activity in Jetpack compose

Activity code which is collecting the flow as state and updating the UI based on the state emitted by the Flow. setContent { val viewModel: MainViewModel = viewModel() val state: State = viewModel.flow.collectAsStateWithLifecycle( …
0
votes
1 answer

How this change from runBlocking to sharedFlow work?

I would like to ask you why does it work? Normally when I used collectLatest with flow my data wasn't collected on time and the return value was empty. I have to use async-await coroutines, but I have read it blocks main thread, so it is not…
0
votes
0 answers

Combine with sharedFlow skip values

I have filters which I change on other fragment when I navigate back it saves these filters. Now, the issue is shared flow from time to time is not triggered and not proper data is displayed. in ViewModel lateinit var archivedSettingsFlow:…
0
votes
1 answer

How to understand complicated sharedflow expression?

I would like to fully understand what happens here. sharedFlow.debounce(250) .onEach(::updateGroupingStrategy) .shareIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), replay = 1) debounce Returns a flow that mirrors…
chrisChris
  • 89
  • 7
0
votes
0 answers

I have a question about SharedFlow with the page lifecycle

Although SharedFlow is non-sticky, each result will only be processed once, but during the upload process, if you return to the desktop, in the absence of a receiving end, SharedFlow will discard existing messages, instead of suspending events and…
0
votes
0 answers

Disable/cancel StateFlow for unit test

In my ViewModel there's a StateFlow which seems to prevent my unit test from ever completing, i.e. the test "hangs". I'm fairly new to the Flow lib and not sure how to cancel/disable said StateFlow so I can run my test as normal. I created a…
0
votes
0 answers

Migrating from livedata to kotlin flow

In the proccess of migration I found out some things that I would like to comment out with people who have good knowledge about this. To be honest, I am not master of flow, used livedata for long time, so now I would like to figure out as much as I…
0
votes
1 answer

how to tee a Kotlin SharedFlow

I wrote a flow that emits integers, and two downstream flows that emit just odd or even numbers. I'm only getting values from the last-created SharedFlow: b: 1 b: 3 b: 5 b: 7 ... Is there a better way to implement tee'ing a SharedFlow? import…
Curtis
  • 536
  • 4
  • 10
0
votes
0 answers

MutableSharedFlow is being re collected again and again

I have the following ViewModel and Fragment - class HeroesViewModel(private val heroesRepository: HeroesRepository) : ViewModel() { private val internalUiState = MutableStateFlow(UiState.Initial) val uiState =…
Alon Shlider
  • 1,187
  • 1
  • 16
  • 46
0
votes
1 answer

Why sharedFlow collect won't execute this line?

I define a sharedFlow in MainViewModel like class MainViewModel : ViewModel{ val _sharedFlow: MutableSharedFlow() val sharedFlow = _sharedFlow.asSharedFlow() } Then I have a activity lifecycleScope.launch { …
0
votes
1 answer

how to emit value from built flow object

My question is that how we can emit a value from a built flow object like this: class Sample { var flow: Flow = null fun sendRequest(){ flow = flow{} requestWrapper.flowResponse = flow } fun getResponse(){ …
0
votes
1 answer

Android LiveData advantage than other observable libraries

In 2022, What scenario can imagine LiveData is better than other observable libraries such as StateFlow, SharedFlow, Coroutine Channel and etc.