Android-components: Let's get rid of ThreadUtils

Created on 20 Nov 2018  路  1Comment  路  Source: mozilla-mobile/android-components

Most of the things in ThreadUtils shouldn't be needed anymore.

Let's:

  • Deprecate it.
  • Remove everything that can be done better with Coroutines
  • If anything is left over: Do we still need that and if yes could it be replaced with something that works with Coroutines?
鈱笍 code

Most helpful comment

Some notes of what can be done better with coroutines:

assertOnUiThread

As far as I know, no Kotlin shortcut for this.

postToBackgroundThread

- postToBackgroundThread {
+ withContext(Dispatchers.IO) {
    // blocking code
  }

postToMainThread

- postToMainThread(Runnable {
+ withContext(Dispatchers.Main) {
    // UI thread code
- })
+ }

postToMainThreadDelayed

- postToMainThreadDelayed(Runnable {
+ delay(delayInMs)
+ withContext(Dispatchers.Main) {
    // UI thread code
- }, delayInMs)
+ }

setHandlerForTest

kotlinx-coroutines-test offers testing tools for coroutines.

>All comments

Some notes of what can be done better with coroutines:

assertOnUiThread

As far as I know, no Kotlin shortcut for this.

postToBackgroundThread

- postToBackgroundThread {
+ withContext(Dispatchers.IO) {
    // blocking code
  }

postToMainThread

- postToMainThread(Runnable {
+ withContext(Dispatchers.Main) {
    // UI thread code
- })
+ }

postToMainThreadDelayed

- postToMainThreadDelayed(Runnable {
+ delay(delayInMs)
+ withContext(Dispatchers.Main) {
    // UI thread code
- }, delayInMs)
+ }

setHandlerForTest

kotlinx-coroutines-test offers testing tools for coroutines.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcarare picture mcarare  路  5Comments

boek picture boek  路  3Comments

pocmo picture pocmo  路  3Comments

csadilek picture csadilek  路  3Comments

Callek picture Callek  路  4Comments