Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make dispatcherToBlockOn dispatcher based on daemon threads. (#814)
After #798, we changed Dispatcher.IO to custom dispatcher. Dispatcher.IO is based on daemon threads (thread that receives InterruptException on application exit). Our new dispatcher isn't. The proof: ``` import java.util.concurrent.Executors import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.runBlocking fun main() { runBlocking(Dispatchers.IO) { println(Thread.currentThread().isDaemon) // prints true } runBlocking(Executors.newCachedThreadPool().asCoroutineDispatcher()) { println(Thread.currentThread().isDaemon) // prints false } val defaultFactory = Executors.defaultThreadFactory() runBlocking(Executors.newCachedThreadPool { defaultFactory.newThread(it).apply { isDaemon = true } }.asCoroutineDispatcher()) { println(Thread.currentThread().isDaemon) // prints true } } ``` This PR makes threads daemon. Reported in [Kotlin Slack](https://kotlinlang.slack.com/archives/C01D6HTPATV/p1697400320739369) - applications exits too long.
- Loading branch information