Skip to content

Commit 69d9c85

Browse files
committed
Better debug strings for continuations
1 parent bea51d0 commit 69d9c85

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CancellableContinuation.kt

+2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ internal class CancellableContinuationImpl<in T>(
253253
check(dc.dispatcher === this) { "Must be invoked from the context CoroutineDispatcher"}
254254
resumeWithExceptionImpl(exception, MODE_UNDISPATCHED)
255255
}
256+
257+
override fun toString(): String = super.toString() + "[${delegate.toDebugString()}]"
256258
}
257259

258260
private class CompletedIdempotentResult(

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineDispatcher.kt

+11-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ internal class DispatchTask<in T>(
123123
}
124124

125125
override fun toString(): String =
126-
"DispatchTask[$value, cancellable=$cancellable, $continuation]"
126+
"DispatchTask[$value, cancellable=$cancellable, ${continuation.toDebugString()}]"
127127
}
128128

129129
internal class DispatchedContinuation<in T>(
@@ -184,7 +184,16 @@ internal class DispatchedContinuation<in T>(
184184
dispatcher.dispatch(context, DispatchTask(continuation, value,false, true))
185185
}
186186

187-
override fun toString(): String = "DispatchedContinuation[$dispatcher, $continuation]"
187+
override fun toString(): String = "DispatchedContinuation[$dispatcher, ${continuation.toDebugString()}]"
188+
}
189+
190+
// **KLUDGE**: there is no reason to include continuation into debug string until the following ticket is resolved:
191+
// KT-18986 Debug-friendly toString implementation for CoroutineImpl
192+
// (the current string representation of continuation is useless and uses buggy reflection internals)
193+
// So, this function is a replacement that extract a usable information from continuation -> its class name, at least
194+
internal fun Continuation<*>.toDebugString(): String = when (this) {
195+
is DispatchedContinuation -> toString()
196+
else -> this::class.java.name
188197
}
189198

190199
internal fun <T> Continuation<T>.resumeCancellable(value: T) = when (this) {

0 commit comments

Comments
 (0)