@@ -7,7 +7,17 @@ import kotlin.coroutines.CoroutineContext
7
7
import kotlin.coroutines.EmptyCoroutineContext
8
8
9
9
private const val DEBUG_PROPERTY_NAME = " kotlinx.coroutines.debug"
10
- private val DEBUG = CoroutineId ::class .java.desiredAssertionStatus() || System .getProperty(DEBUG_PROPERTY_NAME ) != null
10
+
11
+ private val DEBUG = run {
12
+ val value = System .getProperty(DEBUG_PROPERTY_NAME )
13
+ when (value) {
14
+ " auto" , null -> CoroutineId ::class .java.desiredAssertionStatus()
15
+ " on" , " " -> true
16
+ " off" -> false
17
+ else -> error(" System property '$DEBUG_PROPERTY_NAME ' has unrecognized value '$value '" )
18
+ }
19
+ }
20
+
11
21
private val COROUTINE_ID = AtomicLong ()
12
22
13
23
@PublishedApi
@@ -47,14 +57,18 @@ public fun currentCoroutineContextOrDefault(default: CoroutineDispatcher): Corou
47
57
* The [context] for the new coroutine must be explicitly specified and must include [CoroutineDispatcher] element.
48
58
* This function shall be used to start new coroutines.
49
59
*
50
- * **Debugging facilities:** When assertions are enabled or when "kotlinx.coroutines.debug" system property
51
- * is set, every coroutine is assigned a unique consecutive identifier. Every thread that executes
52
- * a coroutine has its name modified to include the name and identifier of the currently currently running coroutine.
53
- *
60
+ * **Debugging facilities:** In debug mode every coroutine is assigned a unique consecutive identifier.
61
+ * Every thread that executes a coroutine has its name modified to include the name and identifier of the
62
+ * currently currently running coroutine.
54
63
* When one coroutine is suspended and resumes another coroutine in the same thread and a [CoroutineDispatcher]
55
64
* is not explicitly or dispatcher executes continuation in the same thread, then the thread name displays
56
65
* the whole stack of coroutine descriptions that are being executed on this thread.
57
66
*
67
+ * Enable debugging facilities with "`kotlinx.coroutines.debug`" system property, use the following values:
68
+ * * "`auto`" (default mode) -- enabled when assertions are enabled with "`-ea`" JVM option.
69
+ * * "`on`" or empty string -- enabled.
70
+ * * "`off`" -- disabled.
71
+ *
58
72
* Coroutine name can be explicitly assigned using [CoroutineName] context element.
59
73
* The string "coroutine" is used as a default name.
60
74
*/
0 commit comments