Kotlinx.coroutines: The name for the main Android dispatcher

Created on 7 Sep 2018  路  4Comments  路  Source: Kotlin/kotlinx.coroutines

We should finalize the name for the main Android dispatcher for 1.0 release of coroutines. The current name is UI, but Android documentation names the corresponding concept "the main thread" (see also here https://github.com/Kotlin/kotlinx.coroutines/issues/427#issuecomment-403562661). Arguably, with structured concurrency (see #410) this name would not be used much often, but we still need to make sure it is clearly named.

for 1.0 release

Most helpful comment

I strongly prefer MainThread for a few reasons:

  • The main thread is not always the UI thread
  • The main thread is still needed in locations like application subtypes, services, brodcast receivers, job scheduler jobs, etc. where there is no UI to speak of.

All 4 comments

I strongly prefer MainThread for a few reasons:

  • The main thread is not always the UI thread
  • The main thread is still needed in locations like application subtypes, services, brodcast receivers, job scheduler jobs, etc. where there is no UI to speak of.

I agree with @JakeWharton

it's possible for a UI thread to be different from the main thread in the case of system apps with multiple views on different threads. Therefore, you should annotate methods associated with an app's view hierarchy with @ UiThread and annotate only methods associated with an app's lifecycle with @ MainThread.

https://developer.android.com/studio/write/annotations#thread-annotations

Currently Android integration uses the Main thread.
Moreover it is better use "Main" instead of "UI" here

Seconding Main which matches existing APIs (https://developer.android.com/reference/android/os/Looper#getMainLooper()) and is more accurate.

While we are at it, lets reopen discussion #41 about structures for all dispatcher name. Now, when we are about to release structured concurrency (#410) you would not have to mention the dispatcher names too often, so it makes sense to group them all.

Was this page helpful?
0 / 5 - 0 ratings