Created
November 27, 2018 09:23
-
-
Save shkschneider/fe2cc0610ebffda9d758b6853188fbac 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
@UiThread | |
fun getUsers(context: Context): LiveData<List<User>> { | |
if (!::users.isInitialized) { | |
users = MutableLiveData() | |
users.postValue(MyDatabase.get(context).users().getAll()) | |
GlobalScope.launch(Dispatchers.Main) { | |
val usersFromDb: List<User> = async(Dispatchers.IO) { | |
return@async MyDatabase.get(context).users().getAll() | |
}.await() | |
users.value = usersFromDb | |
} | |
} | |
return users | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment