Skip to content

Instantly share code, notes, and snippets.

View diefferson's full-sized avatar
🎯
Focusing

Diefferson Santos diefferson

🎯
Focusing
View GitHub Profile
@diefferson
diefferson / AsyncLiveData.kt
Created October 12, 2018 12:59 — forked from STAR-ZERO/AsyncLiveData.kt
LiveData + Kotlin Coroutine
// compile "org.jetbrains.kotlinx:kotlinx-coroutines-android:0.16"
// compile "android.arch.lifecycle:runtime:1.0.0-alpha3"
// compile "android.arch.lifecycle:extensions:1.0.0-alpha3"
// kapt "android.arch.lifecycle:compiler:1.0.0-alpha3"
class AsyncLiveData<T> private constructor(private val exec: suspend () -> T) : LiveData<T>() {
private var observer: Observer<T>? = null
private var job: Job? = null