Kotlin Coroutine 개념
·
Kotlin
Kotlin Coroutine 개념 예시 suspend fun fetchDocs() { // Dispatchers.Main val result = get("https://developer.android.com") // Dispatchers.IO for `get` show(result) // Dispatchers.Main } suspend fun get(url: String) = withContext(Dispatchers.IO) { /* ... */ } 예시에서 get() 은 기본 스레드에서 실행되지만 네트워크 요청을 시작하기 전 Coroutine 을 정지(suspend)합니다. 네트워크 요청이 완료되면 get() 은 callback 을 사용하여 기본 스레드에 알리는 대신 정지(spspend)된 Corou..