-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CoroutineDispatcher's names #41
Comments
I'm not convinced that a potential name clash is actually a problem. Can you give some examples as to where you have encountered it? The argument against this change is that dispatchers are exclusively used as arguments to various coroutine builders: |
This issue raised on my first approach on coroutines. If we consider Java's List then we can have ArrayList, LinkedList, EmptyList and so on. It is simple to aggregate all these on a single cap. "Unbounded" and "Swing" are too heterogeneous names, and the argument for "async" method is "CoroutineContext" not "CoroutineDispatcher", so I can wrongly use "Swing" as a coroutine's L&F. In simple case the code a trained programmer can understand correctly the statement: |
Hi @elizarov, Any suggestion in well accepted, thanks. |
I'd give it a short name, like |
There is also a related issue of naming various functions that take dispatchers as their arguments. Might renaming |
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 The cost is that we have to use the prefix. The benefit is that IDE now lists all dispatchers for me. |
@voddan That is an interesting idea. I like it more than just giving them longer names. like XXXDispatcher. |
I agree that the coroutine dispatcher naming conflict isn't really an issue. It's somewhat nice that it's short and sweet for something that will be commonly used: |
Closing this issue. We'll leave the general naming approach as it is (a few top-level names). |
I've reopened this discussion in light of structured concurrency (#410) and the proposed change for the Android dispatcher (#533). The goal is to address two concerns:
The concrete proposal I have on the table is to group all the dispatcher references under
|
I think |
While As |
@chrisbanes Let me clarify, that |
* Dispatchers.Default — a default dispatcher for background asynchronous tasks (currently backed by FJP commonPool, a new dispatcher in the future). * Dispatchers.IO — a dispatcher for blocking background operations (#79). * Dispatchers.Main — a dispatcher for Android Main Thread (#533). * Dispatchers.Swing — a dispatcher for Swing Event Dispatch Thread. * Dispatchers.JavaFx — a dispatcher for JavaFx Application Thread. * Old dispatchers are deprecated, CommonPool is deprecated, too. * awaitPulse() in JavaFx and awaitFrame() in Android are top-level funs. * Introduced HandlerDispatcher, SwingDispatcher, and JavaFxDispatcher types in the corresponding UI modules for type-safety and future extensions Fixes #41
* Dispatchers.Default — a default dispatcher for background asynchronous tasks (currently backed by FJP commonPool, a new dispatcher in the future). * Dispatchers.IO — a dispatcher for blocking background operations (#79). * Dispatchers.Main — a dispatcher for Android Main Thread (#533). * Dispatchers.Swing — a dispatcher for Swing Event Dispatch Thread. * Dispatchers.JavaFx — a dispatcher for JavaFx Application Thread. * Old dispatchers are deprecated, CommonPool is deprecated, too. * awaitPulse() in JavaFx and awaitFrame() in Android are top-level funs. * Introduced HandlerDispatcher, SwingDispatcher, and JavaFxDispatcher types in the corresponding UI modules for type-safety and future extensions Fixes #41 Fixes #533
* Dispatchers.Default — a default dispatcher for background asynchronous tasks (currently backed by FJP commonPool, a new dispatcher in the future). * Dispatchers.IO — a dispatcher for blocking background operations (#79). * Dispatchers.Main — a dispatcher for Android Main Thread (#533). * Dispatchers.Swing — a dispatcher for Swing Event Dispatch Thread. * Dispatchers.JavaFx — a dispatcher for JavaFx Application Thread. * Old dispatchers are deprecated, CommonPool is deprecated, too. * awaitPulse() in JavaFx and awaitFrame() in Android are top-level funs. * Introduced HandlerDispatcher, SwingDispatcher, and JavaFxDispatcher types in the corresponding UI modules for type-safety and future extensions Fixes #41 Fixes #533
I like the flexibility of @LouisCAD's suggestion. Being able to provide both I still think |
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.
The text was updated successfully, but these errors were encountered: