Conversation
- 일시 중단 함수는 코루틴이 아니며 순차적으로 실행된다. - `coroutineScope`를 사용하여 일시 중단 함수 내에서 병렬 실행이 가능한 `CoroutineScope`를 생성할 수 있다. - `supervisorScope`를 사용하여 일시 중단 함수 내 코루틴의 예외 전파를 제한할 수 있다. docs(study-coroutine.md): 일시 중단 함수 내용 추가
- `join`/`await` 호출 시 코루틴의 스레드 양보 및 일시 중단, 재개 순서 확인 - `yield`를 사용한 스레드 양보를 통해 무한 루프 탈출 가능성 확인 - `CoroutineDispatcher`에 의한 코루틴 실행 스레드 변경 관찰
코루틴은 서브루틴과 달리 서로 스레드 사용 권한을 양보하며 함께 실행된다. `delay`, `join`, `await`, `yield` 함수는 스레드를 양보한다. 코루틴이 스레드를 양보하면 일시 중단되며, 재개될 때 `CoroutineDispatcher`를 통해 다른 스레드에서 실행될 수 있다. `Thread.sleep`은 스레드를 양보하지 않고 블로킹한다.
- 예외 전파 처리를 하지 않아 터지는 학습 목적 테스트를 만들었습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
설명
코루틴의 일시 중단 함수와 내부 동작 방식을 더 잘 이해하기 위한 학습 테스트를 추가
주요 변경 사항
CoroutineSuspendTest.kt:일시 중단 함수가 코루틴이 아니며 순차적으로 실행됨을 확인하는 테스트를 추가했습니다.
coroutineScope를 사용하여 일시 중단 함수 내에서 병렬 실행이 가능한CoroutineScope를 생성하는 테스트를 추가했습니다.supervisorScope를 사용하여 일시 중단 함수 내 코루틴의 예외 전파를 제한하는 테스트를 추가했습니다.CoroutineUnderstoodTest.kt:join/await호출 시 코루틴의 스레드 양보, 일시 중단 및 재개 순서를 검증하는 테스트를 추가했습니다.yield함수를 사용하여 스레드를 명시적으로 양보함으로써 무한 루프 상황을 탈출할 수 있음을 확인하는 테스트를 추가했습니다.CoroutineDispatcher에 의해 코루틴 실행 스레드가 변경될 수 있음을 관찰하는 테스트를 추가했습니다.study-coroutine.md:'일시 중단 함수' 섹션을 추가하여 일시 중단 함수의 개념, 특징 및
coroutineScope,supervisorScope사용법을 설명했습니다.'코루틴의 이해' 섹션을 추가하여 코루틴이 서브루틴과 어떻게 다른지, 스레드 양보 메커니즘 (
delay,join,await, yield)및CoroutineDispatcher의 역할에 대해 정리했습니다. 또한,Thread.sleep과의 차이점을 명시했습니다.