여러 비동기 함수에서 데이터를 동시에 얻어야 하는 경우를 생각해 보자. 코루틴 스코프 함수가 소개되기 전에 사용한 방법들 suspend fun getUserProfile(): UserProfileData { val user = getUserData() // 1초 후 val notifications = getNotifications() // 1초 후 return UserProfileData( user = user, notifications = notifications, )}먼저 중단 함수에서 중단 함수를 호출하는 방법이 있다. 하지만 이런 방식은 작업이 동시에 진행되지 않는다.하나의 함수에서 데이터를 얻는 데 1초씩 걸리기 때문에 총 2초가 걸린다. susp..
코루틴은 잡히지 않은 예외가 발생했을 때 종료된다스레드도 동일한 경우에 종료되지만, 차이점이 있다.코루틴 빌더는 부모도 종료시키고, 종료된 부모는 자식들까지 모두 취소시킨다는 것이다. fun main(): Unit = runBlocking { launch { launch { delay(1000) throw Error("Some error") } launch { delay(2000) println("Will not be printed") } launch { delay(500) println("W..