kotlinx.coroutines
kotlinx.coroutines copied to clipboard
`limitedParallelism` does not propagate the full `CoroutineContext` to the underlying dispatcher
trafficstars
import kotlinx.coroutines.*
import kotlin.coroutines.*
object MyDispatcher: CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
println(context)
block.run()
}
}
fun main() {
val newDispatcher = MyDispatcher.limitedParallelism(2)
newDispatcher.dispatch(CoroutineName("Hi!"), Runnable { })
}
prints
LimitedDispatcher@4459eb14
No CoroutineName in sight.
https://pl.kotl.in/86W-MnSGn
This bug was not reported to us as any production issue, but was found accidentally by reading https://github.com/Kotlin/kotlinx.coroutines/blob/6c6df2b850382887462eeaf51f21f58bd982491d/kotlinx-coroutines-core/common/src/internal/LimitedDispatcher.kt#L43-L54