You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New approach eagerly copies corresponding elements to avoid accidental top-level reuse and also provides merge capability in case when an element is being overwritten. Merge capability is crucial in tracing scenarios to properly preserve the state of linked thread locals
Co-authored-by: dkhalanskyjb <[email protected]>
Copy file name to clipboardExpand all lines: kotlinx-coroutines-core/api/kotlinx-coroutines-core.api
+3-1
Original file line number
Diff line number
Diff line change
@@ -141,7 +141,8 @@ public final class kotlinx/coroutines/CompletionHandlerException : java/lang/Run
141
141
}
142
142
143
143
public abstract interface class kotlinx/coroutines/CopyableThreadContextElement : kotlinx/coroutines/ThreadContextElement {
144
-
public abstract fun copyForChildCoroutine ()Lkotlinx/coroutines/CopyableThreadContextElement;
144
+
public abstract fun copyForChild ()Lkotlinx/coroutines/CopyableThreadContextElement;
145
+
public abstract fun mergeForChild (Lkotlin/coroutines/CoroutineContext$Element;)Lkotlin/coroutines/CoroutineContext;
145
146
}
146
147
147
148
public final class kotlinx/coroutines/CopyableThreadContextElement$DefaultImpls {
@@ -156,6 +157,7 @@ public abstract interface class kotlinx/coroutines/CopyableThrowable {
156
157
}
157
158
158
159
public final class kotlinx/coroutines/CoroutineContextKt {
160
+
public static final fun newCoroutineContext (Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
159
161
public static final fun newCoroutineContext (Lkotlinx/coroutines/CoroutineScope;Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
fold(false) { result, it -> result || it isCopyableThreadContextElement<*> }
41
+
42
+
/**
43
+
* Folds two contexts properly applying [CopyableThreadContextElement] rules when necessary.
44
+
* The rules are the following:
45
+
* * If neither context has CTCE, the sum of two contexts is returned
46
+
* * Every CTCE from the left-hand side context that does not have a matching (by key) element from right-hand side context
47
+
* is [copied][CopyableThreadContextElement.copyForChild] if [isNewCoroutine] is `true`.
48
+
* * Every CTCE from the left-hand side context that has a matching element in the right-hand side context is [merged][CopyableThreadContextElement.mergeForChild]
49
+
* * Every CTCE from the right-hand side context that hasn't been merged is copied
50
+
* * Everything else is added to the resulting context as is.
0 commit comments