Category "kotlin-coroutines"

How to change main scope to another in recyclerview, adapter?

This is my code in adapter using recyclerView. How to improve this code to not use Main Scope, but to use scope that could be disposal? I need to have access to

Using rememberCoroutineScope() vs LaunchedEffect

Context In Jetpack compose, we have the option of using rememberCoroutineScope() as well as using the LaunchedEffect composable in order to use coroutines / run

My MutableStateFlow doesnt emit when called from suspend function in test

I am trying to write tests for my Repository which provides access to my Room database. For this, I wrote a Mock Database and a mock DAO: My Database: abstract

Kotlin Flow - Some emitted events not received when collect

I am using MutableStateFlow. My flow type is sealed class with different states (Loading, Success, Error, etc). Initial value of my flow is empty: private val _

After a coroutine scope is cancel, can it still be used again?

When we have a coroutine scope, when it is canceled, can it be used again? e.g. for the below, when I have scope.cancel, the scope.launch no longer work @Te

Kotlin Flow returned from Room does not update when an insert is performed from another Fragment/ViewModel

I have a Room database that returns a Flow of objects. When I insert a new item into the database, the Flow's collect function only triggers if the insert was p

How we can mock a CoroutineDatabase in ktor?

I use the KMongo tool How we can mock a Coroutine Database? How can we mock our database in a koin module? Is there a way to do this? Thanks for guiding me Meth

How to access lifecycleScope of the host fragment from a custom view?

I need to use coroutines inside a custom view. After watching this talk, I believe my best option is to use lifecycleScope as the coroutine scope, so that it wi

How to Unsubscribe from coroutine flows right after RoomDb call

I'm trying to query Room database(action 1) and then based on the returned results perform another action on the same table. however I noticed that every time I

Cancel viewModelScope and re-use it later on

I'm using Coroutines for dealing with async jobs: viewModelScope.launch { val userResponse = getUsers() //suspendable function } What I want to do is stop

How to call suspend function from Service Android?

How to provide scope or how to call suspend function from Service Android? Usually, activity or viewmodel provides us the scope, from where we can launch suspen

Kotlin Flows map

I have an issue regarding kotlin flow merging. See below fun. suspend fun method(filter: String): Flow<List<Model>> { // Search. val models: List&l

I am getting this issue, I tried using kotlin coroutines and Async still getting the same Calling this from Your main thread can lead to deadlock,

I also made another class that implements runnable to make a new thread still it's now working, Also tried with Aynctask. At last, I made a view model but still

How to create an extension function with multiple receivers in Kotlin?

I want my extension function to have a couple of receivers. For example, I want function handle to be able to call methods of both CoroutineScope and Iterable i

Do I need to mention the coroutine dispatcher while working with Retrofit and Room?

Recently I saw this - Most data sources already provide main-safe APIs like the suspend method calls provided by Room or Retrofit. Your repository can take adva

How to safely (lifecycle aware) .collectAsState() a StateFlow?

I'm trying to follow the official guidelines to migrate from LiveData to Flow/StateFlow with Compose, as per these articles: A safer way to collect flows from A

Parallel processing values emitted by flow in Kotlin

Kotlin code runBlocking { flow { for (i in 0..4) { println("Emit $i") emit(i) }} .onEach { if (it%2 == 0) delay(20

What does "intrinsic" implementation mean in Kotlin?

When browsing through Kotlin source code, I found that in some places NotImplementedError is thrown: public suspend inline val coroutineContext: CoroutineContex

How to make "inappropriate blocking method call" appropriate?

I am currently trying to leverage kotlin coroutines more. But I face a problem: when using moshi or okhttp inside these coroutines I get a warning: "inappropri

Logcat does not show an error message when an exception is thrown in the coroutine (Xiaomi)

It shows only I/Process: Sending signal. PID: xxxxx SIG: 9 I have tried to enable debug mode System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON) b