• Igor Demin's avatar
    Make dispatcherToBlockOn dispatcher based on daemon threads. (#814) · 1cbde7b1
    Igor Demin authored
    After https://github.com/JetBrains/skiko/pull/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.
    1cbde7b1
Name
Last commit
Last update
.github/workflows Loading commit data...
.run Loading commit data...
gradle/wrapper Loading commit data...
samples Loading commit data...
skiko Loading commit data...
.gitignore Loading commit data...
DEVELOPMENT.md Loading commit data...
LICENSE Loading commit data...
README.md Loading commit data...
gradle.properties Loading commit data...
gradlew Loading commit data...
gradlew.bat Loading commit data...
settings.gradle.kts Loading commit data...