Skip to content

sellmair/looper

Repository files navigation

Looper

A simple Looper-Thread implementation for Android

GitHub top language Build Status Bintray

Usage

gradle
dependencies { 
    implement "io.sellmair:looper:1.0.0-RC.0"
}
Starting the thread
val thread = LooperThread.start()
Wait for startup
// Current thread will wait until looper thread is fully booted
thread.awaitStartup()
Executing
// 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")
}
Getting a Handler
// 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()
Stopping the thread
thread.quit() // will discard all pending messages
thread.quitSafely() // will process all currently pending messages first