Skip to content

Commit dc9fd1c

Browse files
committed
Nicer toString implementations for CommonPool & Unconfined dispatchers
1 parent d6bb148 commit dc9fd1c

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ object CommonPool : CoroutineDispatcher() {
8282
}
8383
usePrivatePool = false
8484
}
85+
86+
override fun toString(): String = "CommonPool"
8587
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal fun resetCoroutineId() {
4848
public object Unconfined : CoroutineDispatcher() {
4949
override fun isDispatchNeeded(context: CoroutineContext): Boolean = false
5050
override fun dispatch(context: CoroutineContext, block: Runnable) { throw UnsupportedOperationException() }
51+
override fun toString(): String = "Unconfined"
5152
}
5253

5354
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public abstract class CoroutineDispatcher :
9191
"The dispatcher to the right of `+` just replaces the dispatcher the left of `+`.",
9292
level = DeprecationLevel.ERROR)
9393
public operator fun plus(other: CoroutineDispatcher) = other
94+
95+
// for nicer debugging
96+
override fun toString(): String =
97+
"${this::class.java.simpleName}@${Integer.toHexString(System.identityHashCode(this))}"
98+
9499
}
95100

96101
internal class DispatchedContinuation<in T>(

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ internal class EventLoopImpl(
128128
}
129129
}
130130

131-
override fun toString(): String = "EventLoopImpl@${Integer.toHexString(System.identityHashCode(this))}"
132-
133131
private fun scheduleQueued(queuedTask: QueuedTask): Boolean {
134132
if (parentJob == null) {
135133
queue.addLast(queuedTask)

0 commit comments

Comments
 (0)