25 lines
659 B
Kotlin
25 lines
659 B
Kotlin
package com.gh.common
|
|
|
|
import android.os.Handler
|
|
import android.os.Looper
|
|
import java.util.concurrent.Executor
|
|
import java.util.concurrent.Executors
|
|
|
|
object AppExecutor {
|
|
@JvmStatic
|
|
var ioExecutor = Executors.newSingleThreadExecutor()
|
|
@JvmStatic
|
|
var uiExecutor = MainThreadExecutor()
|
|
|
|
class MainThreadExecutor : Executor {
|
|
private val mainThreadHandler = Handler(Looper.getMainLooper())
|
|
|
|
override fun execute(command: Runnable) {
|
|
mainThreadHandler.post(command)
|
|
}
|
|
|
|
fun executeWithDelay(command: Runnable, delay: Long) {
|
|
mainThreadHandler.postDelayed(command, delay)
|
|
}
|
|
}
|
|
} |