Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
12.96k stars 1.85k forks source link

Consider deprecation cycle for `CoroutineDispatcher.invoke` #4199

Open JakeWharton opened 1 month ago

JakeWharton commented 1 month ago

CoroutineDispatcher.invoke, a function used as such:

Dispatchers.IO {
  stuff
}

is a shorter version of withContext that only works with dispatchers.

Does this function need to exist? It seems to predate structured concurrency and is so terse that it offers no indication as to its underlying behavior. Does it launch a new coroutine? Does it move the current coroutine? Does the supplied block honor structured concurrency?

I personally have a hard time finding a reason for this function to continue to exist.

CLOVIS-AI commented 1 month ago

For context, it was originally added in #428 as an experiment. As far as I know, it is very rarely used (if at all) in the ecosystem.

dkhalanskyjb commented 1 month ago

Very few usages found: https://grep.app/search?q=.IO%20%7B&case=true&filter[lang][0]=Kotlin https://grep.app/search?q=Dispatchers.Default%20%7B&case=true&filter[lang][0]=Kotlin https://grep.app/search?q=Dispatchers.Main%20%7B&case=true&words=true&filter[lang][0]=Kotlin

I personally find this to be non-idiomatic modern Kotlin. Thing { } looks to me like a builder of some sort. So, I'm for this.

qwwdfsad commented 1 month ago

We can try and proceed with it in RC2 along with other deprecations

dkhalanskyjb commented 1 month ago

I'm not sure what I expected, but the deprecation doesn't look pretty in the IDE! Screenshot_20240801_134245 Given how rare this is, I don't think this should stop us, though.

dkhalanskyjb commented 1 month ago

Auto-replacement also doesn't work

JakeWharton commented 1 month ago

Finding some good IntelliJ bugs/feature requests at least!