전체 글 196

[Android] LiveData - Flow로 마이그레이션

#1 이전 글 [Kotlin] Coroutines Flow - StateFlow#1 개요 StateFlowA SharedFlow that represents a read-only state with a single updatable data value that emits updates to the value to its collectors. A state flow is a hot flow because its active instance exists independently of the presence of collectokenel.tistory.comStateFlow에 대해 다룬 이전 글에서 이어진다. LiveData가 쓰인 XML 기반 View 프로젝트를 수정해, LiveData를 StateFlow로..

[Android] Jetpack Compose - StateFlow와 SharedFlow

#1 이전 글 [Kotlin] Coroutines Flow - StateFlow#1 개요 StateFlowA SharedFlow that represents a read-only state with a single updatable data value that emits updates to the value to its collectors. A state flow is a hot flow because its active instance exists independently of the presence of collectokenel.tistory.comStateFlow에 대해 다룬 이전 글에서 이어진다. State가 쓰인 Jetpack Compose 프로젝트를 수정해, State 대신 StateFlow를..

[Kotlin] Coroutines Flow - StateFlow

#1 개요 StateFlowA SharedFlow that represents a read-only state with a single updatable data value that emits updates to the value to its collectors. A state flow is a hot flow because its active instance exists independently of the presence of collectors. Its current valukotlinlang.orgSharedFlow의 일종인 StateFlow에 대해 살펴본다. #2 SharedFlow와의 비교이름에서 알 수 있듯, StateFlow는 기존 SharedFlow에 State의 특성을 결합한 Flow다..

[Kotlin] Coroutines Flow - Intermediate operator

#1 개요#1-1 중간 연산자 (Intermediate operator) Asynchronous Flow | Kotlin kotlinlang.org중간 연산자에 대해 살펴본다. #1-2 중간 연산자의 구조중간 연산자는 이름 그대로의 역할을 수행한다. 이름에 있는 '중간'은, emit과 collect 사이 '중간'을 의미한다. 시작점이 emit이고 도착점이 collect인 배수관 속 물의 흐름을 intermediate operator가 하이재킹하는 느낌이라고 보면 된다. 여기서 중요한 점은, 앞으로(=미래에) emit될 데이터를 변형하는 연산자는 결코 아니라는 것이다. 이미(=과거에) emit된 데이터에 특정 연산을 가하여, collect에 전달하는 연산자다. 중간 연산자이니 말이다. #2 Flow에 가용..

[Kotlin] Coroutines Flow - Back pressure와 그 처리

#1 개요Coroutines Flow를 사용할 때 생길 수 있는 현상인 백 프레셔(Back pressure)에 대해 살펴본다. 또, 백 프레셔를 처리하는 방법도 살펴본다. 이 때, 백 프레셔는 에러가 아닌 자연스러운 현상일 뿐이다. 따라서, 백 프레셔를 해결한다는 표현은 정확하지 않다. 백 프레셔에 대처한다는 표현이 옳다. #2 백 프레셔#2-1 백 프레셔가 없는 코드import kotlinx.coroutines.*import kotlinx.coroutines.flow.Flowimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.flow// 1초마다 1씩 증가하는 countfun startCountUp(count: Mu..

Cold Flow와 Hot Flow (SharedFlow)

#1 Cold Flow와 Hot Flow#1-1 개요데이터 스트림은 크게 Cold Flow와 Hot Flow로 나눌 수 있다. 이 분류 기준에 대해 알아본다. 또, Kotlin의 Coroutines Flow를 활용해 간단한 Cold Flow 및 Hot Flow를 구현해본다.  #1-2 훌륭한 비유 What is the hot flow and cold flow in coroutines and the difference between them?I am mastering Kotlin coroutines and trying to figure out 1- what is hot flow and cold flow ? 2- what is the main difference between them? 3- when to ..

[Android] Coroutines Flow - Jetpack Compose에서 사용하기

#1 개요 [Kotlin] Coroutines Flow - 기초#1 Coroutines Flow#1-1 개요 FlowFlow An asynchronous data stream that sequentially emits values and completes normally or with an exception. Intermediate operators on the flow such as map, filter, take, zip, etc are functions that are applied to the upstkenel.tistory.com위에서 다룬 Coroutines Flow를 Jetpack Compose에 적용시켜본다. 여기서 말하는 '적용'이란, 단순한 사용이 아니라 Flow 객체를 State로서 ..

어떻게 살아야 하는가?

# 어떻게 살아야 하는가?나는 늘 스스로에게 물었다. "어떻게 살아야 하는가?" 질문은 언제나 하나였으나, 대답(방법론)은 늘 달랐다. 대충 생각해도 8살부터는 이런 질문을 해왔다. 지금까지 모인 대답의 갯수를 전부 합하면 수백수천 가지는 족히 될 것이다. 과장이 아니다. 나는 어느 때는 컴퓨터 게임을 할 수 있음에도, 그 선택지 대신 '대답'에 심취하여 생각에 잠긴 때도 많았기 때문이다. 나에게 있어 그 대답이란 나의 인생과 이 세상을 관통하는 하나의 진실이어야 했고, 나는 그 진실에 늘 매달렸다. # 슬로건그러다 어느 순간부터 지쳐버리고 말았다. 1. 어떤 대답을 오랜 고민 끝에 도출한다. 2. 이 세상의 법칙(후술할 혼돈)에 의해 대답이 산산이 부셔지고 논파된다. 3. "내가 틀린 대답을 했을 뿐이..

카테고리 없음 2024.08.05

[Kotlin] Coroutines Flow - 기초

#1 Coroutines Flow#1-1 개요 FlowFlow An asynchronous data stream that sequentially emits values and completes normally or with an exception. Intermediate operators on the flow such as map, filter, take, zip, etc are functions that are applied to the upstream flow or flows and return a dokotlinlang.orgFlow는 내부적으로 Coroutine을 사용해 비동기적으로 데이터 스트림을 처리하는 API다. 이를 반응형 프로그래밍이라고도 한다. 반응형 프로그래밍을 한 마디로 정의하면, ..