6강 Structured Concurrency
- 코루틴이 완료될 때
COMPLETING
상태와 COMPLETED
의 2개의 상태가 필요한 이유
- 자식 코루틴을 기댜려야 하기 때문
- 부모 코루틴이 완료 되어도 (
COMPLETING
) 자식 코루틴이 실패하면 CANCELLING
상태로 돌아간다.
- 자식 코루틴의 예외가 부모 코루틴에게 전파되면 부모는 다른 자식 코루틴에게 취소 요청을 보낸다.
- Structured Concurrency
- 수많은 코루틴이 유실되거나 누수 되지 않도록 보장하는 것
- 코드 내 에러가 유실되지 않고 적절히 보고될 수 있도록 보장한다.
- ex) 자식 코루틴이 부모로 예외를 전파하는 것과, 부모가 자식에게 취소 요청을 보내는 것
취소와 예외. Structured Concurrency 총 정리
- 자식 코루틴에서 예외 발생 시 Structured Concurrency에 의해
- 부모 코루틴이 취소된다.
- 부모 코루틴의 다른 자식 코루틴들도 취소된다.
- 자식 코루틴에서 예외가 발생하지 않아도 부모 코루틴이 취소되면 자식 코루틴들이 취소된다.
- 다만
CancellationException
은 정상적인 취소로 간주하기에 부모에게 예외를 전파하지도 않고, 다른 자식 코루틴을 취소하지도 않는다.