https://github.com/sellmair/looper
A simple Android Looper-Thread implementation
https://github.com/sellmair/looper
android android-lib android-library kotlin kotlin-library looper thread threading
Last synced: 12 months ago
JSON representation
A simple Android Looper-Thread implementation
- Host: GitHub
- URL: https://github.com/sellmair/looper
- Owner: sellmair
- License: mit
- Created: 2018-09-03T12:40:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-23T15:50:49.000Z (over 7 years ago)
- Last Synced: 2025-01-10T10:33:17.301Z (about 1 year ago)
- Topics: android, android-lib, android-library, kotlin, kotlin-library, looper, thread, threading
- Language: Kotlin
- Size: 142 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Looper
A simple Looper-Thread implementation for Android

[](https://travis-ci.org/sellmair/looper)

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