Relative Content

Tag Archive for kotlinkotlin-coroutines

How to cancel the coroutine inside runBlocking?

I have code which scans rows from a database and produces those rows in batches as a producer channel. I want to concurrently process the batches as new ones come in. I then want to watch for errors, and if any occur, cancel both the producer channel and the data processor. Here is my sample code:

Why thread name is DefaultDispatcher-worker even though I specify function to run on Dispatchers.IO? And why the number of threads is so high?

A beginner question about how dispatchers work in Kotlin. I run this piece of code to test a theory and it printed out the thread names are “DefaultDispatcher-worker-xx” even though I specifically call launch(Dispatchers.IO). I never actually see the log showing as Dispatchers.IO anywhere in my code despite using withContext(Dispatchers.IO) in various places. How does it work?

Creating telegram bot API wrapper in Kotlin with Coroutines

I need a suggestion regarding the architecture of the telegram bot API wrapper. So basically I need a way to handle updates efficiently. I have checked how kotlin-telgram-bot does it. And it has a Courotine dispatcher on a single thread Executors.newSingleThreadExecutor().asCoroutineDispatcher(). Handling its update as follows: