Created
June 29, 2019 17:48
-
-
Save jeremyrempel/95c38c7c5465bda2fc4c62bca4434ace to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainFragmentViewModel @Inject constructor(myService: MyService) : ViewModel() { | |
private val data: MutableLiveData<String> = MutableLiveData() | |
init { | |
// call async service with callback | |
myService.getData(data::setValue) | |
} | |
fun getData(): LiveData<String> = data | |
} | |
class MyService @Inject constructor() { | |
// do something async and respond via callback. Could be RX, Coroutine or ExecutorService | |
fun getData(onComplete: (String) -> Unit) { | |
return onComplete("Hello From the Future") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment