@@ -14,13 +14,18 @@ import kotlin.coroutines.*
1414 * Default instance of coroutine dispatcher.
1515 */
1616internal object DefaultScheduler : ExperimentalCoroutineDispatcher() {
17- val IO = blocking(systemProp(IO_PARALLELISM_PROPERTY_NAME , 64 .coerceAtLeast(AVAILABLE_PROCESSORS )))
17+ val IO : CoroutineDispatcher = LimitingDispatcher (
18+ this ,
19+ systemProp(IO_PARALLELISM_PROPERTY_NAME , 64 .coerceAtLeast(AVAILABLE_PROCESSORS )),
20+ " Dispatchers.IO" ,
21+ TASK_PROBABLY_BLOCKING
22+ )
1823
1924 override fun close () {
20- throw UnsupportedOperationException (" $DEFAULT_SCHEDULER_NAME cannot be closed" )
25+ throw UnsupportedOperationException (" $DEFAULT_DISPATCHER_NAME cannot be closed" )
2126 }
2227
23- override fun toString (): String = DEFAULT_SCHEDULER_NAME
28+ override fun toString (): String = DEFAULT_DISPATCHER_NAME
2429
2530 @InternalCoroutinesApi
2631 @Suppress(" UNUSED" )
@@ -85,7 +90,7 @@ public open class ExperimentalCoroutineDispatcher(
8590 */
8691 public fun blocking (parallelism : Int = BLOCKING_DEFAULT_PARALLELISM ): CoroutineDispatcher {
8792 require(parallelism > 0 ) { " Expected positive parallelism level, but have $parallelism " }
88- return LimitingDispatcher (this , parallelism, TASK_PROBABLY_BLOCKING )
93+ return LimitingDispatcher (this , parallelism, null , TASK_PROBABLY_BLOCKING )
8994 }
9095
9196 /* *
@@ -98,7 +103,7 @@ public open class ExperimentalCoroutineDispatcher(
98103 public fun limited (parallelism : Int ): CoroutineDispatcher {
99104 require(parallelism > 0 ) { " Expected positive parallelism level, but have $parallelism " }
100105 require(parallelism <= corePoolSize) { " Expected parallelism level lesser than core pool size ($corePoolSize ), but have $parallelism " }
101- return LimitingDispatcher (this , parallelism, TASK_NON_BLOCKING )
106+ return LimitingDispatcher (this , parallelism, null , TASK_NON_BLOCKING )
102107 }
103108
104109 internal fun dispatchWithContext (block : Runnable , context : TaskContext , tailDispatch : Boolean ) {
@@ -130,8 +135,9 @@ public open class ExperimentalCoroutineDispatcher(
130135}
131136
132137private class LimitingDispatcher (
133- val dispatcher : ExperimentalCoroutineDispatcher ,
134- val parallelism : Int ,
138+ private val dispatcher : ExperimentalCoroutineDispatcher ,
139+ private val parallelism : Int ,
140+ private val name : String? ,
135141 override val taskMode : Int
136142) : ExecutorCoroutineDispatcher(), TaskContext, Executor {
137143
@@ -190,7 +196,7 @@ private class LimitingDispatcher(
190196 }
191197
192198 override fun toString (): String {
193- return " ${super .toString()} [dispatcher = $dispatcher ]"
199+ return name ? : " ${super .toString()} [dispatcher = $dispatcher ]"
194200 }
195201
196202 /* *
0 commit comments