23 lines
874 B
Kotlin
23 lines
874 B
Kotlin
package android.os
|
|
|
|
class Looper {
|
|
companion object {
|
|
private val main = Looper()
|
|
@JvmStatic fun getMainLooper() = main
|
|
@JvmStatic fun myLooper() = main
|
|
}
|
|
}
|
|
// Deterministic FIFO main-thread queue; no Android device/real sockets in this test.
|
|
class Handler(val looper: Looper) {
|
|
companion object {
|
|
val queue = java.util.concurrent.ConcurrentLinkedQueue<Runnable>()
|
|
val delayed = mutableListOf<Runnable>()
|
|
fun drain() { while (true) (queue.poll() ?: return).run() }
|
|
}
|
|
fun post(action: Runnable): Boolean { queue.add(action); return true }
|
|
fun postDelayed(action: Runnable, delay: Long): Boolean { delayed.add(action); return true }
|
|
fun removeCallbacks(action: Runnable) { delayed.remove(action); queue.remove(action) }
|
|
}
|
|
|
|
object SystemClock { fun elapsedRealtime() = System.nanoTime() / 1_000_000 }
|