순차화

기존에 다른 코루틴에 보내진 작업의 결과를 수신하려면 다음과 같이 코드를 만들어야 했다 suspend fun main() { val deferred: Deferred = CoroutineScope(Dispatchers.IO).async { "Async Result" } val result = deferred.await() println(result) } Deferred로 결과값을 감싼 다음 await() 메서드를 통해 해당 값이 수신될 때까지 기다려야 한다. withContext를 이용한 비동기 작업 순차화 withContext를 이용하면 withContext의 두가지 특성 때문에 이러한 작업을 간단하게 만들 수 있다. withContext 블록의 마지막 줄의 값이 반환 값이 된다. withContext..
Dev.Cho
'순차화' 태그의 글 목록