Skip to content

Commit fd167db

Browse files
committed
Add documentation
1 parent d612409 commit fd167db

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

kotlinx-coroutines-core/jvm/src/debug/ArtificialStackFrames.kt

+28-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,34 @@
55
package kotlinx.coroutines.debug
66
import kotlinx.coroutines.*
77

8+
/**
9+
* A collection of artificial stack trace elements to be included in stack traces by the coroutines machinery.
10+
*/
811
@InternalCoroutinesApi
912
internal class ArtificialStackFrames {
10-
public fun coroutineCreation(): StackTraceElement = Exception().stackTrace.toList()[0]
11-
public fun coroutineBoundary(): StackTraceElement = Exception().stackTrace.toList()[0]
13+
/**
14+
* Return an artificial stack trace element denoting the boundary between coroutine creation and its execution.
15+
*
16+
* Appearance of this function in stack traces does not mean that it was called. Instead, it is used as a marker
17+
* that separates the part of the stack trace with the code executed in a coroutine from the stack trace of the code
18+
* that launched the coroutine.
19+
*
20+
* In earlier versions of kotlinx-coroutines, this was displayed as "(Coroutine creation stacktrace)", which caused
21+
* problems for tooling that processes stack traces: https://github.com/Kotlin/kotlinx.coroutines/issues/2291
22+
*
23+
* Note that presence of this marker in a stack trace implies that coroutine creation stack traces were enabled.
24+
*/
25+
fun coroutineCreation(): StackTraceElement = Exception().stackTrace[0]
26+
27+
/**
28+
* Return an artificial stack trace element denoting a coroutine boundary.
29+
*
30+
* Appearance of this function in stack traces does not mean that it was called. Instead, when one coroutine invokes
31+
* another, this is used as a marker in the stack trace to denote where the execution of one coroutine ends and that
32+
* of another begins.
33+
*
34+
* In earlier versions of kotlinx-coroutines, this was displayed as "(Coroutine boundary)", which caused
35+
* problems for tooling that processes stack traces: https://github.com/Kotlin/kotlinx.coroutines/issues/2291
36+
*/
37+
fun coroutineBoundary(): StackTraceElement = Exception().stackTrace[0]
1238
}

kotlinx-coroutines-debug/test/StacktraceUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public fun verifyDump(vararg traces: String, ignoredCoroutine: String? = null) {
8181
assertTrue(filtered[0].startsWith("Coroutines dump"))
8282
return
8383
}
84-
// Drop "Coroutine dump" line
84+
// The first line, "Coroutine dump", is dropped. This is not `zip` because not having enough dumps is an error.
8585
trace.drop(1).withIndex().forEach { (index, value) ->
8686
if (ignoredCoroutine != null && value.contains(ignoredCoroutine)) {
8787
return@forEach

0 commit comments

Comments
 (0)