kotlinx.coroutines icon indicating copy to clipboard operation
kotlinx.coroutines copied to clipboard

Ability to specify a limited dispatcher name

Open dovchinnikov opened this issue 1 year ago • 2 comments

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.

dovchinnikov avatar Jan 25 '24 13:01 dovchinnikov

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.

vsalavatov avatar Jan 25 '24 16:01 vsalavatov

Current solution in IJ

https://github.com/JetBrains/intellij-community/blob/bf4170d658dde3633362026d80ac49a3d79076b4/platform/util/coroutines/src/dispatchers.kt#L17

dovchinnikov avatar Feb 06 '24 17:02 dovchinnikov