From 6ce20af13648a55970177ada70d7a78cc895d3b4 Mon Sep 17 00:00:00 2001 From: Lee Jaeheon Date: Sun, 9 Mar 2025 13:03:50 +0900 Subject: [PATCH 1/2] Simplify newFixedThreadPoolContext using apply --- kotlinx-coroutines-core/jvm/src/ThreadPoolDispatcher.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kotlinx-coroutines-core/jvm/src/ThreadPoolDispatcher.kt b/kotlinx-coroutines-core/jvm/src/ThreadPoolDispatcher.kt index 96074f5de3..151f598168 100644 --- a/kotlinx-coroutines-core/jvm/src/ThreadPoolDispatcher.kt +++ b/kotlinx-coroutines-core/jvm/src/ThreadPoolDispatcher.kt @@ -10,9 +10,8 @@ public actual fun newFixedThreadPoolContext(nThreads: Int, name: String): Execut require(nThreads >= 1) { "Expected at least one thread, but $nThreads specified" } val threadNo = AtomicInteger() val executor = Executors.newScheduledThreadPool(nThreads) { runnable -> - val t = Thread(runnable, if (nThreads == 1) name else name + "-" + threadNo.incrementAndGet()) - t.isDaemon = true - t + Thread(runnable, if (nThreads == 1) name else name + "-" + threadNo.incrementAndGet()) + .apply { isDaemon = true } } return Executors.unconfigurableExecutorService(executor).asCoroutineDispatcher() } From 4d4c2a133b6201e7d6e32f321b75666bf02ea73c Mon Sep 17 00:00:00 2001 From: Lee Jaeheon Date: Sun, 9 Mar 2025 13:04:37 +0900 Subject: [PATCH 2/2] Remove unused import from Dispatchers --- kotlinx-coroutines-core/jvm/src/Dispatchers.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/kotlinx-coroutines-core/jvm/src/Dispatchers.kt b/kotlinx-coroutines-core/jvm/src/Dispatchers.kt index a5e8da4c40..a6acc129cc 100644 --- a/kotlinx-coroutines-core/jvm/src/Dispatchers.kt +++ b/kotlinx-coroutines-core/jvm/src/Dispatchers.kt @@ -2,7 +2,6 @@ package kotlinx.coroutines import kotlinx.coroutines.internal.* import kotlinx.coroutines.scheduling.* -import kotlin.coroutines.* /** * Name of the property that defines the maximal number of threads that are used by [Dispatchers.IO] coroutines dispatcher.