Coroutines Context

    Coroutines Flow 4편 - Flow의 수집이 일어나는 Context, Flow Buffering - buffer, conflate, collectLatest

    Flow의 수집이 일어나는 Context Flow의 수집은 언제나 Coroutine을 호출하는 Context상에서 일어난다. 예를 들어 만약 simple이라 불리는 Flow가 있다면, 다음의 코드의 simple Flow는 구체적인 구현과 상관없이 코드 작성자가 지정한 Context상에서 실행된다 : withContext(context) { simple().collect { value -> println(value) // run in the specified context } } Flow의 이러한 성질은 컨텍스트 보존(context preservation)이라 불린다. 따라서 기본적으로 flow { ... } 빌더 내부의 코드는 해당 Flow의 collector가 제공하는 Context 상에서 실행된다. ..

    Coroutine Context와 Dispatcher 4편 - 부모 Coroutine의 책임, Coroutines에 이름 짓기, Context 요소들 결합하기

    부모 Coroutine의 책임 부모 Coroutine은 언제나 자식들이 완료될 때까지 기다린다. 부모는 모든 자식들의 실행을 명시적으로 추적하지 못하고, 그들이 모두 끝날 때까지 기다리기 위해 Job.join을 사용할 필요가 없다. // launch a coroutine to process some kind of incoming request val request = launch { repeat(3) { i -> // launch a few children jobs launch { delay((i + 1) * 200L) // variable delay 200ms, 400ms, 600ms println("Coroutine $i is done") } } println("request: I'm done and..

    Coroutine Context와 Dispatcher 2편 - Coroutines와 Threads 디버깅 하기 : IntelliJ 사용, 로깅 사용

    Coroutine Context와 Dispatcher 2편 - Coroutines와 Threads 디버깅 하기 : IntelliJ 사용, 로깅 사용

    Coroutines와 Threads 디버깅 하기 Coroutines는 하나의 스레드에서 일시 중단한 다음 다른 스레드에서 재개될 수 있다. 싱글 스레드를 가진 Dispatcher에서도 특별한 도구가 없으면 Coroutine이 언제, 어디서 무엇을 하는지 알기 어렵다.*1 IDEA를 사용해 디버깅 하기 Kotlin Plugin인 Coroutine Debugger은 Intellij IDEA에서 Coroutines 디버깅을 간단하게 할 수 있도록 한다. 📍 디버깅은 kotlinx-coroutines-core 1.3.8 혹은 그 이후 버전에서부터만 동작한다. Debug tool window는 Coroutines 탭을 포함한다. 이 탭에서 현재 실행 중이거나 일시 중단된 Coroutine 모두에 대한 정보를 확인..

    Coroutine Context와 Dispatcher 1편 - Dispatchers와 Threads, Unconfined vs confined dispatcher

    Coroutines는 언제나 Kotlin 표준 라이브러리에 정의된 CoroutineContext 타입 값으로 표현되는 일부 Context 상에서 실행된다. Coroutine의 Context는 다양한 요소의 집합이다. 주요 요소는 이전 섹션에서 본 Coroutine의 Job과 이번 섹션에서 다룰 Dispatcher이다. Dispatchers와 Threads Coroutine Context에는 해당 Coroutine의 실행에 사용되는 단일 스레드나 복수의 스레드를 결정하는 CoroutineDispatcher(CoroutineDispatcher 문서를 확인)가 포함 된다. Coroutine Dispatcher은 Coroutine의 실행될 사용될 스레드를 특정 스레드로 제한하거나 스레드풀에 분배하거나, 제한 없..