A simple Looper-Thread implementation for Android
dependencies {
implement "io.sellmair:looper:1.0.0-RC.0"
}
val thread = LooperThread.start()
// Current thread will wait until looper thread is fully booted
thread.awaitStartup()
// Dispatches a task to the looper thread
// If thread is not started: Will be queued and
// executed once the thread started.
thread.execute {
print("I will be executed by the looper thread")
}
// Will be null if the thread is not yet started
val handler = thread.handler
// Never null: Will wait for thread to start up if necessary
// Is cheap if thread is already started
val handler = thread.handler()
thread.quit() // will discard all pending messages
thread.quitSafely() // will process all currently pending messages first