Skip to content

Commit d78084b

Browse files
elizarovqwwdfsad
authored andcommitted
Better docs on coroutines debugging property
* Mention in the guide that `-ea` turns it on. * Give a link to DEBUG_PROPERTY_NAME instead of newCoroutineContext. The later does not have details on its page anymore, since the details were only mentioned in JVM version. * Move description in of debugging facilities to DEBUG_PROPERTY_NAME in the code.
1 parent 60101b8 commit d78084b

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

docs/coroutine-context-and-dispatchers.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ The `log` function prints the name of the thread in square brackets and you can
221221
thread, but the identifier of the currently executing coroutine is appended to it. This identifier
222222
is consecutively assigned to all created coroutines when debugging mode is turned on.
223223

224-
You can read more about debugging facilities in the documentation for [newCoroutineContext] function.
224+
> Debugging mode is also turned on when JVM is run with `-ea` option.
225+
You can read more about debugging facilities in the documentation for [DEBUG_PROPERTY_NAME] property.
225226

226227
### Jumping between threads
227228

@@ -695,7 +696,7 @@ that should be implemented.
695696
[ExecutorCoroutineDispatcher.close]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/close.html
696697
[runBlocking]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html
697698
[delay]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/delay.html
698-
[newCoroutineContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/new-coroutine-context.html
699+
[DEBUG_PROPERTY_NAME]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html
699700
[withContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html
700701
[isActive]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/is-active.html
701702
[CoroutineScope.coroutineContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html

kotlinx-coroutines-core/common/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ helper function. [NonCancellable] job object is provided to suppress cancellatio
6565

6666
This module provides debugging facilities for coroutines (run JVM with `-ea` or `-Dkotlinx.coroutines.debug` options)
6767
and [newCoroutineContext] function to write user-defined coroutine builders that work with these
68-
debugging facilities.
68+
debugging facilities. See [DEBUG_PROPERTY_NAME] for more details.
6969

7070
This module provides a special CoroutineContext type [TestCoroutineCoroutineContext][kotlinx.coroutines.test.TestCoroutineContext] that
7171
allows the writer of code that contains Coroutines with delays and timeouts to write non-flaky unit-tests for that code allowing these tests to
@@ -124,6 +124,7 @@ Low-level primitives for finer-grained control of coroutines.
124124
[Deferred.await]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/await.html
125125
[Deferred.onAwait]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/on-await.html
126126
[newCoroutineContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/new-coroutine-context.html
127+
[DEBUG_PROPERTY_NAME]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html
127128
<!--- INDEX kotlinx.coroutines.sync -->
128129
[kotlinx.coroutines.sync.Mutex]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html
129130
[kotlinx.coroutines.sync.Mutex.lock]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,7 @@ internal actual fun createDefaultDispatcher(): CoroutineDispatcher =
2626
* Creates context for the new coroutine. It installs [Dispatchers.Default] when no other dispatcher nor
2727
* [ContinuationInterceptor] is specified, and adds optional support for debugging facilities (when turned on).
2828
*
29-
* **Debugging facilities:** In debug mode every coroutine is assigned a unique consecutive identifier.
30-
* Every thread that executes a coroutine has its name modified to include the name and identifier of the
31-
* currently running coroutine.
32-
* When one coroutine is suspended and resumes another coroutine that is dispatched in the same thread,
33-
* then the thread name displays
34-
* the whole stack of coroutine descriptions that are being executed on this thread.
35-
*
36-
* Enable debugging facilities with "`kotlinx.coroutines.debug`" ([DEBUG_PROPERTY_NAME]) system property
37-
* , use the following values:
38-
* * "`auto`" (default mode, [DEBUG_PROPERTY_VALUE_AUTO]) -- enabled when assertions are enabled with "`-ea`" JVM option.
39-
* * "`on`" ([DEBUG_PROPERTY_VALUE_ON]) or empty string -- enabled.
40-
* * "`off`" ([DEBUG_PROPERTY_VALUE_OFF]) -- disabled.
41-
*
42-
* Coroutine name can be explicitly assigned using [CoroutineName] context element.
43-
* The string "coroutine" is used as a default name.
44-
*
45-
* **Note: This is an experimental api.**
46-
* Behavior of this function may change in the future with respect to its support for debugging facilities.
29+
* See [DEBUG_PROPERTY_NAME] for description of debugging facilities on JVM.
4730
*/
4831
@ExperimentalCoroutinesApi
4932
public actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext {

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,26 @@ import java.util.concurrent.atomic.*
1212
import kotlin.internal.InlineOnly
1313

1414
/**
15-
* Name of the property that controls coroutine debugging. See [newCoroutineContext][CoroutineScope.newCoroutineContext].
15+
* Name of the property that controls coroutine debugging.
16+
*
17+
* ### Debugging facilities
18+
*
19+
* In debug mode every coroutine is assigned a unique consecutive identifier.
20+
* Every thread that executes a coroutine has its name modified to include the name and identifier of
21+
* the currently running coroutine.
22+
*
23+
* Enable debugging facilities with "`kotlinx.coroutines.debug`" ([DEBUG_PROPERTY_NAME]) system property,
24+
* use the following values:
25+
*
26+
* * "`auto`" (default mode, [DEBUG_PROPERTY_VALUE_AUTO]) -- enabled when assertions are enabled with "`-ea`" JVM option.
27+
* * "`on`" ([DEBUG_PROPERTY_VALUE_ON]) or empty string -- enabled.
28+
* * "`off`" ([DEBUG_PROPERTY_VALUE_OFF]) -- disabled.
29+
*
30+
* Coroutine name can be explicitly assigned using [CoroutineName] context element.
31+
* The string "coroutine" is used as a default name.
32+
*
33+
* Debugging facilities are implemented by [newCoroutineContext][CoroutineScope.newCoroutineContext] function that
34+
* is used in all coroutine builders to create context of a new coroutine.
1635
*/
1736
public const val DEBUG_PROPERTY_NAME = "kotlinx.coroutines.debug"
1837

@@ -58,17 +77,17 @@ public interface CopyableThrowable<T> where T : Throwable, T : CopyableThrowable
5877
}
5978

6079
/**
61-
* Automatic debug configuration value for [DEBUG_PROPERTY_NAME]. See [newCoroutineContext][CoroutineScope.newCoroutineContext].
80+
* Automatic debug configuration value for [DEBUG_PROPERTY_NAME].
6281
*/
6382
public const val DEBUG_PROPERTY_VALUE_AUTO = "auto"
6483

6584
/**
66-
* Debug turned on value for [DEBUG_PROPERTY_NAME]. See [newCoroutineContext][CoroutineScope.newCoroutineContext].
85+
* Debug turned on value for [DEBUG_PROPERTY_NAME].
6786
*/
6887
public const val DEBUG_PROPERTY_VALUE_ON = "on"
6988

7089
/**
71-
* Debug turned on value for [DEBUG_PROPERTY_NAME]. See [newCoroutineContext][CoroutineScope.newCoroutineContext].
90+
* Debug turned on value for [DEBUG_PROPERTY_NAME].
7291
*/
7392
public const val DEBUG_PROPERTY_VALUE_OFF = "off"
7493

0 commit comments

Comments
 (0)