본문 바로가기

분류 전체보기55

(Coroutine) 2. Light weight Thread, Job 1. Light weight Thread == Coroutine 코루틴 공식 가이드를 살펴보면 코루틴을 경량화된 쓰레드(Light-weight Thread) 라고 표현하고 있다. 경량화된 쓰레드가 무엇일까? 앞서 살펴본 예시들의 출력 결과를 봐보자. >> runBlocking: main @coroutine#1 >> Hello >> launch: main @coroutine#2 >> World! 출력 결과를 통해 알 수 있듯이 코루틴은 쓰레드 상에서 실행된다. 위 결과는 main 쓰레드에서 수행된 2개의 코루틴에 대한 결과이다. 즉, 코루틴은 쓰레드 없이 단독적으로 수행되거나 다른 수단에 의해 실행될 수 없다는 것을 뜻한다. 그렇기 때문에, 여러 코루틴이 한 쓰레드에서 수행될 수 있지만 코루틴이 동시에 수.. 2022. 9. 12.
(Coroutine) 1. Coroutine Basic 1. Simple Coroutine 코루틴을 만드는 함수는 코루틴 빌더라고 부른다. 코루틴을 만드는 가장 간단한 방법으로 runBlocking 함수가 있다. runBlocking 함수는 코루틴을 만들고, 블록 수행이 끝날 때 까지 다음 코드를 수행하지 못하게 막는 코루틴 빌더이다. runBlocking 함수는 반환 값을 지정해줄 수 있다. 이때, 기본 반환타입은 Unit이다. fun test() = runBlocking { // 반환 타입 : Int ... 3 // 최종 반환 값 } 2. 코루틴 빌더의 수신 객체 runBlocking 블록 안에서 this를 출력했을 때 결과를 살펴보자. fun main() = runBlocking { println(this) } >> "coroutine#1":Blocki.. 2022. 9. 12.
(번역) A safer way to collect flows from Android UIs 이 게시물은 Android Developers Medium에 작성되어있는 A safer way to collect flows from Android UIs를 번역 및 의역하여 정리한 게시물입니다. 잘못된 정보는 댓글로 첨언해주시면 감사하겠습니다. A safer way to collect flows from Android UIs Learn how the repeatOnLifecycle API protects you from wasting resources and why it’s a good default for flow collection in the UI layer. medium.com 안드로이드 UI에서 안전하게 flow 수집하기 안드로이드 앱에서, Kotlin flows는 일반적으로 UI Layer에.. 2022. 8. 31.
(번역) Migrating from LiveData to Kotlin's Flow 이 게시물은 Android Developers Medium에 작성되어있는 Migrating from LiveData to Kotlin's Flow를 번역 및 의역하여 정리한 게시물입니다. 잘못된 정보는 댓글로 첨언해주시면 감사하겠습니다. Migrating from LiveData to Kotlin’s Flow In this post you’ll learn how to expose Flows to a view, how to collect them, and how to fine-tune it to fit specific needs. medium.com LiveData에서 Kotlin Flow로 이전 LiveData는 2017년에 우리에게 필요한 것이었습니다. (Google I/O `17에서의 AAC 공개) .. 2022. 8. 31.