CoroutineDispatcher's names
See original GitHub issueCoroutineDispatcher’s names are too heterogeneous (CommonPool, Unconfined) and programmer isn’t helped to collate these in the same hierarchy. Other CoroutineDispatchers have too common name (Swing, JavaFX) and are subjects to name clash: Look And Feel engine can also expose “Swing” and “JavaFX” singletons.
My prosose is to define a common suffix like “CoroutineDispatcher”, “CDispatcher” or simply “Dispatcher” to grouping names.
I.E.
- CommonDispatcher
- UnconfinedDispatcher
- SwingDispatcher
- JavaFXDispatcher
launch(CommonDispatcher) {
. . .
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:14 (11 by maintainers)
Top Results From Across the Web
Coroutine context and dispatchers - Kotlin
The coroutine context includes a coroutine dispatcher (see CoroutineDispatcher) that determines what thread or threads the corresponding ...
Read more >Kotlin Coroutines dispatchers - Kt. Academy
Garima Jain, Google Developer Expert - Android, also known as @ragdroid works as. Garima Jain. Garima Jain, Google Developer Expert - Android, also...
Read more >Coroutine Context and Dispatchers | Baeldung on Kotlin
CoroutineDispatcher is a subtype of the ContinuationInterceptor element of context. Therefore, it is responsible for determining the execution ...
Read more >Dispatchers in Kotlin Coroutines - AndroidWave
In this post, we will talk about dispatchers, we will learn what is dispatchers in Kotlin Coroutines? How it works in Coroutines. will...
Read more >Dispatchers in Kotlin Coroutines - Amit Shekhar
Dispatchers help Coroutines in deciding the thread on which the task has to be done. We use Coroutines to perform certain tasks efficiently....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My issue with coroutine dispatchers not being organized in a hierarchy is poor discoverability. For example, if I want to use a coroutine builder, but forgot the spelling of a dispatcher I need, there is currently no better option than reading the documentation.
I propose to introduce a global singleton
Dispatcher
for serving as a hierarchy root. Then all coroutine dispatchers can be its extension propertiesval Dispatcher.Unconfined get() = ...
and be used asDispatcher.Unconfined
.The cost is that we have to use the prefix. The benefit is that IDE now lists all dispatchers for me.
I like the flexibility of @LouisCAD’s suggestion. Being able to provide both
Android.Main
(async) andAndroid.UI
(vsync) dispatchers, but I agree with @adamp in https://github.com/Kotlin/kotlinx.coroutines/issues/427#issuecomment-403562661 that having two dispatchers would be confusing too.I still think
Dispatchers.Main
is an unfortunate name since it’s such a generic noun. MaybeDispatchers.Android
to be similar toJavaFx
andSwing
?