Reactive
-
[Coroutine] runBlocking vs coroutineScope 차이는?Reactive/Coroutine 2024. 11. 9. 02:46
runBlocking, coroutineScope 차이점runBlockingrunBlocking 내부에서 새로운 코루틴 스코프를 생성블록 내부의 모든 코루틴이 끝날 때까지 runBlocking이 호출된 쓰레드는 대기주로 main 함수와 같이 비코루틴에서 호출할 때나 테스트 코드에서 코루틴을 사용할 때 일반적인 코드 블록처럼 동작하게 하기 위해 사용됨 coroutineScopesuspend 함수 안에서만 호출할 수 있음coroutineScope는 새로운 코루틴 스코프를 만들지만 현재 쓰레드를 차단하지 않음 1. Coroutine 신규 생성 여부fun main() { runBlocking { println("[Main] ${Thread.currentThread().name}") ..