kotlinx.coroutines
kotlinx.coroutines copied to clipboard
Ability to specify a limited dispatcher name
Use case
We have specific dispatchers, and in coroutine dumps they all look like LimitedDispatcher@xxxxxxxx, and it's not immediately clear where the dispatcher comes from.
The Shape of the API
Make kotlinx.coroutines.CoroutineDispatcher.limitedParallelism accept debugName: String?.
Alternatively, make an extension function fun CoroutineDispatcher.namedDispatcher(debugName: String): CoroutineDispatcher which will return a dispatcher, which delegates to this and has its toString overridden. It can return this as is when debug is off.
Prior Art
kotlinx.coroutines.scheduling.LimitingDispatcher has name.
I'm concerned that .namedDispatcher() can be misused to give a new alias to an existing dispatcher that is used somewhere else. It can potentially make this connection unobvious and, for example, hinder debugging of an issue with concurrency involved.
I think that giving a dispatcher a name should be inseparable from creating one. I believe this would be a safer approach.
Current solution in IJ
https://github.com/JetBrains/intellij-community/blob/bf4170d658dde3633362026d80ac49a3d79076b4/platform/util/coroutines/src/dispatchers.kt#L17