Coroutine이란?
suspend fun fetch(): User = withContext(Dispatchers.IO) {
api.getUser()
}
lifecycleScope.launch { val user = fetch() }구성
- suspend function
- CoroutineScope
- Dispatchers (IO, Main, Default)
- Flow — 리액티브 스트림
Kotlin의 비동기 프로그래밍 구조. suspend 함수로 콜백 헬 탈출.
suspend fun fetch(): User = withContext(Dispatchers.IO) {
api.getUser()
}
lifecycleScope.launch { val user = fetch() }