Questions tagged [kotlin-sharedflow]
52 questions
2
votes
0 answers
How to pause and resume coroutine in Kotlin?
I have a kotlin code like following.
private val faceProcessorFlow = MutableSharedFlow>()
init {
viewModelScope.launch(IO) {
faceProcessorFlow
.onEach {
…

Shiro Ennosuke
- 59
- 6
2
votes
2 answers
Performing single shot operations using SharedFlow without casting to needed value
I have the following SharedFlow in my viewmodel -
class HeroesViewModel(private val heroesRepositoryImpl: HeroesRepositoryImpl) : ViewModel() {
private val _uiState = MutableStateFlow(UiState())
val uiState = _uiState.asStateFlow()
…

Alon Shlider
- 1,187
- 1
- 16
- 46
2
votes
1 answer
SharedFlow.last() never returns
I have a sharedFlow with a replay value of one. But when I am trying to access the last emitted value, the call never returns (while first() does).
Below is my code:
val game = GameSettingsRepository.gameIdFlow.flatMapLatest { gameId ->
…

Uguzon
- 31
- 4
2
votes
1 answer
Does a large amount of extraBufferCapacity in the SharedFlow cause memory leak?
I am working on a chat application with MVVM architecture and I use SharedFlow to transfer incoming messages from Repository to ViewModel. When the user is offline and another user sends a large number of messages to him, as soon as the user is…

Hussein Yaqoobi
- 442
- 5
- 20
2
votes
1 answer
How do you make make a subscriber to a kotlin sharedflow run operations in parallel?
I have a connection to a Bluetooth device that emits data every 250ms
In my viewmodel I wish to subscribe to said data , run some suspending code (which takes approximatelly 1000ms to run) and then present the result.
the following is a simple…

Cruces
- 3,029
- 1
- 26
- 55
2
votes
2 answers
How to create a polling mechanism with kotlin coroutines?
I am trying to create a polling mechanism with kotlin coroutines using sharedFlow and want to stop when there are no subscribers and active when there is at least one subscriber. My question is, is sharedFlow the right choice in this scenario or…

Omkar Amberkar
- 1,952
- 4
- 16
- 21
2
votes
1 answer
Is LiveData hot or cold?
We know that StateFlow and SharedFlow are hot.
StateFlow is a hot flow—it remains in memory as long as the flow is
collected or while any other references to it exist from a garbage
collection root.
SharedFlow is a hot flow that emits values to…

Azim Salimov
- 305
- 1
- 3
- 13
2
votes
0 answers
Android - MutableSharedFlow failed to collect new values with multi subscribers
I want to create a shared view model for communication between MainActivity to fragments.
I decided to use share flow for managing events.
private val _sharedChannel: MutableSharedFlow = MutableSharedFlow(
replay =…

digitalmidges
- 826
- 3
- 13
- 24
1
vote
0 answers
What is the purpose of a `SharedFlowSlot` inside the `SharedFlowImpl` class in Kotlin?
I am trying to understand how a Flow works by looking at the SharedFlowImpl class. As the Flow interface ensures that all classes which implement Flow must override the collect method, it seemed like the obvious choice of method to peruse first. On…

220284
- 95
- 7
1
vote
2 answers
Collect flow but only any new values, not the currently existing value
Currently struggling with this one, and so far no combination of SharedFlow and StateFlow have worked.
I have a flow that might have already started with a value, or not.
Using that flow I want to collect any new values that are emitted after I…

Shadow
- 4,168
- 5
- 41
- 72
1
vote
0 answers
Use shared flow with Mockito in Test
Im currently trying to write test for my method that use shared flow object and get data from it. the problem is when in trying to set method return with mockito, shared flow not emit anything and after 1 minute test result is fails.
My test:
…

Parsa Dehghan
- 11
- 2
1
vote
1 answer
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. While implementing this I get this useless bracket…

Pedro Romano Barbosa
- 587
- 3
- 11
- 29
1
vote
2 answers
Kotlin SharedFlow and debounce operator
I want to debounce the items sent to a shared flow, and consume them after that. Something like this:
private var flow = MutableSharedFlow()
suspend fun search(query: String): Flow {
flow.emit(query)
return flow.debounce(1000).map{…

user1116714
- 315
- 2
- 3
- 12
1
vote
1 answer
Should I emit from a coroutine when collecting from a different flow?
I have a use case where I need to trigger on a specific event collected from a flow and restart it when it closes. I also need to emit all of the events to a different flow. My current implementation looks like this:
scope.launch {
val…

Jakub Licznerski
- 1,008
- 1
- 17
- 33
0
votes
1 answer
SharedFlow collect inside launchedEffect gets executed at last in Android compose
I am using compose in Android. For UI states I use stateFlow in viewmodel & for handling bottom sheet show hide state, I use sharedFlow.
The issue is for sharedFlow collect code in UI, it has to be put inside LaunchedEffect which gets executed at…

Ujjwal Kumar Maharana
- 219
- 1
- 5