From 2ede11b4dd7de939d3d392d2d28e5719520cb544 Mon Sep 17 00:00:00 2001 From: OliverO2 Date: Thu, 27 Jan 2022 14:17:32 +0100 Subject: [PATCH] Fix example code in comment of CopyableThreadContextElement (#3157) --- .../jvm/src/ThreadContextElement.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kotlinx-coroutines-core/jvm/src/ThreadContextElement.kt b/kotlinx-coroutines-core/jvm/src/ThreadContextElement.kt index 1b825cef01..1a960699c7 100644 --- a/kotlinx-coroutines-core/jvm/src/ThreadContextElement.kt +++ b/kotlinx-coroutines-core/jvm/src/ThreadContextElement.kt @@ -97,26 +97,25 @@ public interface ThreadContextElement : CoroutineContext.Element { * is in a coroutine: * * ``` - * class TraceContextElement(val traceData: TraceData?) : CopyableThreadContextElement { - * companion object Key : CoroutineContext.Key - * override val key: CoroutineContext.Key - * get() = Key + * class TraceContextElement(private val traceData: TraceData?) : CopyableThreadContextElement { + * companion object Key : CoroutineContext.Key + * override val key: CoroutineContext.Key = Key * * override fun updateThreadContext(context: CoroutineContext): TraceData? { * val oldState = traceThreadLocal.get() - * traceThreadLocal.set(data) + * traceThreadLocal.set(traceData) * return oldState * } * - * override fun restoreThreadContext(context: CoroutineContext, oldData: TraceData?) { + * override fun restoreThreadContext(context: CoroutineContext, oldState: TraceData?) { * traceThreadLocal.set(oldState) * } * - * override fun copyForChildCoroutine(): CopyableThreadContextElement { + * override fun copyForChildCoroutine(): CopyableThreadContextElement { * // Copy from the ThreadLocal source of truth at child coroutine launch time. This makes * // ThreadLocal writes between resumption of the parent coroutine and the launch of the * // child coroutine visible to the child. - * return CopyForChildCoroutineElement(traceThreadLocal.get()) + * return TraceContextElement(traceThreadLocal.get()?.copy()) * } * } * ```