Most of the things in ThreadUtils shouldn't be needed anymore.
Let's:
Some notes of what can be done better with coroutines:
As far as I know, no Kotlin shortcut for this.
- postToBackgroundThread {
+ withContext(Dispatchers.IO) {
// blocking code
}
- postToMainThread(Runnable {
+ withContext(Dispatchers.Main) {
// UI thread code
- })
+ }
- postToMainThreadDelayed(Runnable {
+ delay(delayInMs)
+ withContext(Dispatchers.Main) {
// UI thread code
- }, delayInMs)
+ }
kotlinx-coroutines-test offers testing tools for coroutines.
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
withContextDispatchers.IOpostToMainThread
withContextDispatchers.MainpostToMainThreadDelayed
withContextdelayDispatchers.MainsetHandlerForTest
kotlinx-coroutines-test offers testing tools for coroutines.