question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CoroutineDispatcher's names

See original GitHub issue

CoroutineDispatcher’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.

  1. CommonDispatcher
  2. UnconfinedDispatcher
  3. SwingDispatcher
  4. JavaFXDispatcher
launch(CommonDispatcher) {
    . . .
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
voddancommented, Jul 21, 2017

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 properties val Dispatcher.Unconfined get() = ... and be used as Dispatcher.Unconfined.

The cost is that we have to use the prefix. The benefit is that IDE now lists all dispatchers for me.

4reactions
chrisbanescommented, Sep 12, 2018

I like the flexibility of @LouisCAD’s suggestion. Being able to provide both Android.Main (async) and Android.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. Maybe Dispatchers.Android to be similar to JavaFx and Swing?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found