Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun start() {
- GlobalScope.launch {
- try {
- val def1 = async { doWork1() }
- val def2 = async { doWork2() }
- Log.d("test", "Result ${def1.await()}, ${def2.await()}")
- } catch (ex: Exception) {
- Log.e("test", "Error", ex)
- }
- }
- }
- private suspend fun doWork1(): Int {
- delay(1000L)
- throw Exception("work 1")
- }
- private suspend fun doWork2(): Int {
- delay(1000L)
- return 1
- }
- fun start() {
- GlobalScope.launch {
- try {
- val value = doWork1()
- Log.d("test", "Result: $value")
- } catch (ex: Exception) {
- Log.e("test", "Error", ex)
- }
- }
- }
- private suspend fun doWork1(): Int {
- delay(1000L)
- throw Exception("work 1")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement