@@ -14,13 +14,18 @@ import kotlin.coroutines.*
14
14
* Default instance of coroutine dispatcher.
15
15
*/
16
16
internal 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
+ )
18
23
19
24
override fun close () {
20
- throw UnsupportedOperationException (" $DEFAULT_SCHEDULER_NAME cannot be closed" )
25
+ throw UnsupportedOperationException (" $DEFAULT_DISPATCHER_NAME cannot be closed" )
21
26
}
22
27
23
- override fun toString (): String = DEFAULT_SCHEDULER_NAME
28
+ override fun toString (): String = DEFAULT_DISPATCHER_NAME
24
29
25
30
@InternalCoroutinesApi
26
31
@Suppress(" UNUSED" )
@@ -85,7 +90,7 @@ public open class ExperimentalCoroutineDispatcher(
85
90
*/
86
91
public fun blocking (parallelism : Int = BLOCKING_DEFAULT_PARALLELISM ): CoroutineDispatcher {
87
92
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 )
89
94
}
90
95
91
96
/* *
@@ -98,7 +103,7 @@ public open class ExperimentalCoroutineDispatcher(
98
103
public fun limited (parallelism : Int ): CoroutineDispatcher {
99
104
require(parallelism > 0 ) { " Expected positive parallelism level, but have $parallelism " }
100
105
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 )
102
107
}
103
108
104
109
internal fun dispatchWithContext (block : Runnable , context : TaskContext , tailDispatch : Boolean ) {
@@ -130,8 +135,9 @@ public open class ExperimentalCoroutineDispatcher(
130
135
}
131
136
132
137
private 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? ,
135
141
override val taskMode : Int
136
142
) : ExecutorCoroutineDispatcher(), TaskContext, Executor {
137
143
@@ -190,7 +196,7 @@ private class LimitingDispatcher(
190
196
}
191
197
192
198
override fun toString (): String {
193
- return " ${super .toString()} [dispatcher = $dispatcher ]"
199
+ return name ? : " ${super .toString()} [dispatcher = $dispatcher ]"
194
200
}
195
201
196
202
/* *
0 commit comments