kotlin2 [Coroutine] 스코프 빌더 - sleep, suspend sleep 해당 스레드를 잠시 쉬어가는 형태. (다른 코루틴이 사용할 수 있도록 양보하지 않음)Thread.sleep(500) : 0.5초동안 delay와 비슷하게 해당 스레드를 쉬게하지만 다른 코루틴이 사용할 수 있게 양보하지 않고 자기가 그대로 가지고 있다.운영체제에 내가 잠시 쉬겠다고 알리는 것 뿐. 다른 스레드에게 넘겨주지는 않음 suspend 코루틴 내에 호출된 함수를 분리할때 필요한 키워드suspend fun doThree() { delay(1000L) println("3!")}suspend fun doOne() { println("1!")}suspend fun doTwo() { delay(500L) println("2!")}fun main() = runBl.. 2024. 5. 4. [Coroutine] 스코프빌더 - runBlocking, launch runBlocking 코루틴을 만드는 가장 간단한 함수. 코루틴을 만들고 수행이 끝날때까지 다른 코드를 수행하지 못하게 막는다 runBlocking 함수 내에서 수신객체(Receiver)는 코루틴이다 runBlocking 함수 내에서 this를 수행 결과 : BlockingCoroutine{Active}@7a46a697 BlockingCoroutine은 CoroutineScope의 자식 코루틴의 시작은 코루틴 스코프다 현재 실행되는 스레드 이름을 확인할 수 있는 방법 : Thread.currentThread().name 코루틴 컨텍스트 : 코루틴을 제대로 처리하기 위한 정보를 파라미터로 가지고 있다 [BlockingCoroutine{Active}@7a46a697, BlockingEventLoop@1.. 2024. 5. 4. 이전 1 다음