We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.job import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlinx.coroutines.ThreadContextElement class MyElement : ThreadContextElement<Unit> { companion object Key : CoroutineContext.Key<MyElement> override val key: CoroutineContext.Key<*> get() = Key override fun updateThreadContext(context: CoroutineContext) { println("update ${context.job}") // both times BlockingCoroutine{Active}@18ef96 } override fun restoreThreadContext(context: CoroutineContext, oldState: Unit) {} } fun main() { runBlocking(MyElement()) { println("outer ${coroutineContext.job}") // BlockingCoroutine{Active}@18ef96 withContext(MyElement()) { println("inner ${coroutineContext.job}") // UndispatchedCoroutine{Active}@2aaf7cc2 } } }
This happens because withContext calls withCoroutineContext with newContext which doesn't include newly created UndispatchedCoroutine.
withContext
withCoroutineContext
newContext
UndispatchedCoroutine
The text was updated successfully, but these errors were encountered:
Properly use UndispatchedCoroutine context for context-specific elements
2ea090f
Fixes #3411
update subtask function to work around withContext behaviour
subtask
d04ffc6
See Kotlin/kotlinx.coroutines#3411 See Kotlin/kotlinx.coroutines#3414 GitOrigin-RevId: 234f21de1899b48425f97193ca63769246b54173
4a5892f
No branches or pull requests
This happens because
withContext
callswithCoroutineContext
withnewContext
which doesn't include newly createdUndispatchedCoroutine
.The text was updated successfully, but these errors were encountered: