Created
January 30, 2021 17:50
-
-
Save GauravChaddha1996/acc9e8936247bab745d7b542d20129e8 to your computer and use it in GitHub Desktop.
This file contains 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
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