@@ -10,7 +10,7 @@ import java.util.concurrent.atomic.*
10
10
import kotlin.coroutines.experimental.*
11
11
12
12
/* *
13
- * Name of the property that control coroutine debugging. See [newCoroutineContext].
13
+ * Name of the property that controls coroutine debugging. See [newCoroutineContext].
14
14
*/
15
15
public const val DEBUG_PROPERTY_NAME = " kotlinx.coroutines.debug"
16
16
@@ -56,14 +56,34 @@ internal val useCoroutinesScheduler = systemProp(COROUTINES_SCHEDULER_PROPERTY_N
56
56
}
57
57
58
58
/* *
59
- * This is the default [CoroutineDispatcher] that is used by all standard builders like
59
+ * The default [CoroutineDispatcher] that is used by all standard builders like
60
60
* [launch], [async], etc if no dispatcher nor any other [ContinuationInterceptor] is specified in their context.
61
61
*
62
62
* It is currently equal to [CommonPool], but the value is subject to change in the future.
63
+ * You can set system property "`kotlinx.coroutines.scheduler`" (either no value or to the value of "`on`")
64
+ * to use an experimental coroutine dispatcher that shares threads with [IO] dispatcher and thus can switch to
65
+ * [IO] context without performing an actual thread context switch.
63
66
*/
64
67
@Suppress(" PropertyName" )
65
68
public actual val DefaultDispatcher : CoroutineDispatcher =
66
- if (useCoroutinesScheduler) ExperimentalCoroutineDispatcher () else CommonPool
69
+ if (useCoroutinesScheduler) BackgroundDispatcher else CommonPool
70
+
71
+ /* *
72
+ * Name of the property that defines the maximal number of threads that are used by [IO] coroutines dispatcher.
73
+ */
74
+ public const val IO_PARALLELISM_PROPERTY_NAME = " kotlinx.coroutines.io.parallelism"
75
+
76
+ /* *
77
+ * The [CoroutineDispatcher] that is designed for offloading blocking IO tasks to a shared pool of threads.
78
+ *
79
+ * Additional threads in this pool are created and are shutdown on demand.
80
+ * The number of threads used by this dispatcher is limited by the value of
81
+ * "`kotlinx.coroutines.io.parallelism`" ([IO_PARALLELISM_PROPERTY_NAME]) system property.
82
+ * It defaults to the limit of 64 threads or the number of cores (whichever is larger).
83
+ */
84
+ public val IO by lazy {
85
+ BackgroundDispatcher .blocking(systemProp(IO_PARALLELISM_PROPERTY_NAME , 64 .coerceAtLeast(AVAILABLE_PROCESSORS )))
86
+ }
67
87
68
88
/* *
69
89
* Creates context for the new coroutine. It installs [DefaultDispatcher] when no other dispatcher nor
0 commit comments