Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GauravChaddha1996/acc9e8936247bab745d7b542d20129e8 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/acc9e8936247bab745d7b542d20129e8 to your computer and use it in GitHub Desktop.
val ceh = CoroutineExceptionHandler { _, throwable ->
launch (Dispatchers.Main) { showFailedUI() }
}
launch(Dispatchers.Default + ceh) {
val apiCall1Result = async {
val r1 = apiCall1()
if(r1.status=="failed") {
throw Exception("api call 1 fails")
}
}
val apiCall2Result = async {
val r2 = apiCall2()
if(r2.status=="failed") {
throw Exception("api call 2 fails")
}
}
val combinedResult = apiCall1Result.await() +
apiCall2Result.await()
launch(Dispatchers.Main) {
showSuccessUI(combinedResult)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment