Category "kotlin-coroutines"

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

MutableStateFlow force update / notify collector

MutableStateFlow doesn't notify collectors if the updated value equals the old value (source). I've found a workaround for this, but it doesn't scale well for c

Ktor - kotlinx.coroutines.channels.ClosedReceiveChannelException: Channel was closed

I am receiving back this kotlinx.coroutines.channels.ClosedReceiveChannelException upon about 50% of my api calls to a post url through Ktor HttpClient. Our cod

How to step through suspend function calls when debugging Kotlin coroutines

How is it possible to debug Kotlin code when stepping into or out of a "suspend" function? (see example below). fun mainFunction() = runBlocking { println

AsyncTask as kotlin coroutine

Typical use for AsyncTask: I want to run a task in another thread and after that task is done, I want to perform some operation in my UI thread, namely hiding a

How to implement timer with Kotlin coroutines

I want to implement timer using Kotlin coroutines, something similar to this implemented with RxJava: Flowable.interval(0, 5, TimeUnit.SECONDS)

Flow message not delivered in unit test

I have a consumer that reads messages off MutableSharedFlow (which acts as an EventBus in my application). I am trying to write a unit test to show that passing

Suspend function 'callGetApi' should be called only from a coroutine or another suspend function

I am calling suspended function from onCreate(...) override fun onCreate(savedInstanceState: Bundle?) { ... ... callGetApi() } and the suspended

KMM on iOS: There is no event loop. Use runBlocking { ... } to start one

I'm trying to use coroutines in a Kotlin Multiplatform project. I'm not experienced in either. I'm trying to call this function fun startFlow { coroutineSco