@@ -19,76 +19,12 @@ public const val IO_PARALLELISM_PROPERTY_NAME: String = "kotlinx.coroutines.io.p
19
19
* Groups various implementations of [CoroutineDispatcher].
20
20
*/
21
21
public actual object Dispatchers {
22
- /* *
23
- * The default [CoroutineDispatcher] that is used by all standard builders like
24
- * [launch][CoroutineScope.launch], [async][CoroutineScope.async], etc.
25
- * if no dispatcher nor any other [ContinuationInterceptor] is specified in their context.
26
- *
27
- * It is backed by a shared pool of threads on JVM. By default, the maximal level of parallelism used
28
- * by this dispatcher is equal to the number of CPU cores, but is at least two.
29
- * Level of parallelism X guarantees that no more than X tasks can be executed in this dispatcher in parallel.
30
- */
31
22
@JvmStatic
32
23
public actual val Default : CoroutineDispatcher = DefaultScheduler
33
24
34
- /* *
35
- * A coroutine dispatcher that is confined to the Main thread operating with UI objects.
36
- * This dispatcher can be used either directly or via [MainScope] factory.
37
- * Usually such dispatcher is single-threaded.
38
- *
39
- * Access to this property may throw [IllegalStateException] if no main thread dispatchers are present in the classpath.
40
- *
41
- * Depending on platform and classpath it can be mapped to different dispatchers:
42
- * - On JS and Native it is equivalent of [Default] dispatcher.
43
- * - On JVM it is either Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by
44
- * [`ServiceLoader`](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html).
45
- *
46
- * In order to work with `Main` dispatcher, the following artifacts should be added to project runtime dependencies:
47
- * - `kotlinx-coroutines-android` for Android Main thread dispatcher
48
- * - `kotlinx-coroutines-javafx` for JavaFx Application thread dispatcher
49
- * - `kotlinx-coroutines-swing` for Swing EDT dispatcher
50
- *
51
- * In order to set a custom `Main` dispatcher for testing purposes, add the `kotlinx-coroutines-test` artifact to
52
- * project test dependencies.
53
- *
54
- * Implementation note: [MainCoroutineDispatcher.immediate] is not supported on Native and JS platforms.
55
- */
56
25
@JvmStatic
57
26
public actual val Main : MainCoroutineDispatcher get() = MainDispatcherLoader .dispatcher
58
27
59
- /* *
60
- * A coroutine dispatcher that is not confined to any specific thread.
61
- * It executes initial continuation of the coroutine in the current call-frame
62
- * and lets the coroutine resume in whatever thread that is used by the corresponding suspending function, without
63
- * mandating any specific threading policy. Nested coroutines launched in this dispatcher form an event-loop to avoid
64
- * stack overflows.
65
- *
66
- * ### Event loop
67
- * Event loop semantics is a purely internal concept and have no guarantees on the order of execution
68
- * except that all queued coroutines will be executed on the current thread in the lexical scope of the outermost
69
- * unconfined coroutine.
70
- *
71
- * For example, the following code:
72
- * ```
73
- * withContext(Dispatchers.Unconfined) {
74
- * println(1)
75
- * withContext(Dispatchers.Unconfined) { // Nested unconfined
76
- * println(2)
77
- * }
78
- * println(3)
79
- * }
80
- * println("Done")
81
- * ```
82
- * Can print both "1 2 3" and "1 3 2", this is an implementation detail that can be changed.
83
- * But it is guaranteed that "Done" will be printed only when both `withContext` are completed.
84
- *
85
- *
86
- * Note that if you need your coroutine to be confined to a particular thread or a thread-pool after resumption,
87
- * but still want to execute it in the current call-frame until its first suspension, then you can use
88
- * an optional [CoroutineStart] parameter in coroutine builders like
89
- * [launch][CoroutineScope.launch] and [async][CoroutineScope.async] setting it to
90
- * the value of [CoroutineStart.UNDISPATCHED].
91
- */
92
28
@JvmStatic
93
29
public actual val Unconfined : CoroutineDispatcher = kotlinx.coroutines.Unconfined
94
30
0 commit comments