Skip to content

Commit 33220fc

Browse files
authored
Remove docs about Dispatchers.kt that replicate the common code (#3614)
We update the docs in Dispatchers.common.kt, but JVM's Dispatchers.kt also has its own version of it, which is accessible via the "JVM" tab of the docs: <https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html> The docs there are outdated, so we remove them.
1 parent cca82e7 commit 33220fc

File tree

2 files changed

+3
-66
lines changed

2 files changed

+3
-66
lines changed

kotlinx-coroutines-core/common/src/Dispatchers.common.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public expect object Dispatchers {
1515
* [launch][CoroutineScope.launch], [async][CoroutineScope.async], etc
1616
* if neither a dispatcher nor any other [ContinuationInterceptor] is specified in their context.
1717
*
18-
* It is backed by a shared pool of threads on JVM. By default, the maximum number of threads used
18+
* It is backed by a shared pool of threads on JVM and Native. By default, the maximum number of threads used
1919
* by this dispatcher is equal to the number of CPU cores, but is at least two.
2020
*/
2121
public val Default: CoroutineDispatcher
@@ -27,7 +27,7 @@ public expect object Dispatchers {
2727
* Access to this property may throw an [IllegalStateException] if no main dispatchers are present in the classpath.
2828
*
2929
* Depending on platform and classpath, it can be mapped to different dispatchers:
30-
* - On JVM it is either the Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by the
30+
* - On JVM it is either the Android main thread dispatcher, JavaFx, or Swing EDT dispatcher. It is chosen by the
3131
* [`ServiceLoader`](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html).
3232
* - On JS it is equivalent to the [Default] dispatcher with [immediate][MainCoroutineDispatcher.immediate] support.
3333
* - On Native Darwin-based targets, it is a dispatcher backed by Darwin's main queue.
@@ -37,6 +37,7 @@ public expect object Dispatchers {
3737
* - `kotlinx-coroutines-android` &mdash; for Android Main thread dispatcher
3838
* - `kotlinx-coroutines-javafx` &mdash; for JavaFx Application thread dispatcher
3939
* - `kotlinx-coroutines-swing` &mdash; for Swing EDT dispatcher
40+
* - `kotlinx-coroutines-test` &mdash; for mocking the `Main` dispatcher in tests via `Dispatchers.setMain`
4041
*/
4142
public val Main: MainCoroutineDispatcher
4243

kotlinx-coroutines-core/jvm/src/Dispatchers.kt

-64
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,12 @@ public const val IO_PARALLELISM_PROPERTY_NAME: String = "kotlinx.coroutines.io.p
1919
* Groups various implementations of [CoroutineDispatcher].
2020
*/
2121
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-
*/
3122
@JvmStatic
3223
public actual val Default: CoroutineDispatcher = DefaultScheduler
3324

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-
*/
5625
@JvmStatic
5726
public actual val Main: MainCoroutineDispatcher get() = MainDispatcherLoader.dispatcher
5827

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-
*/
9228
@JvmStatic
9329
public actual val Unconfined: CoroutineDispatcher = kotlinx.coroutines.Unconfined
9430

0 commit comments

Comments
 (0)