Skip to content

Instantly share code, notes, and snippets.

@HarryTylenol
Created August 5, 2019 14:16
Show Gist options
  • Save HarryTylenol/46ee79ef8d21921c7b7174c40ba5e190 to your computer and use it in GitHub Desktop.
Save HarryTylenol/46ee79ef8d21921c7b7174c40ba5e190 to your computer and use it in GitHub Desktop.
0003_3
private fun createStateForRequest(request: suspend () -> Unit) =
// LiveData (Lifecycle) 2.2.0-alph01 버전 부터 지원
liveData(Dispatchers.IO) {
emit(NetworkState.loading)
try {
request()
emit(NetworkState.success)
} catch (e: IOException) {
e.printStackTrace()
emit(NetworkState.failed(e))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment