woowacourse-study / 2023-BookOverFlow

'5기 안드로이드'라서 최강 스터디인건가? 아니면 최강 스터디라서 '5기 안드로이드'인가?
9 stars 0 forks source link

코루틴(플로우) - 2 면접 질문 #124

Open Choisehyeon opened 2 weeks ago

Choisehyeon commented 2 weeks ago
Choisehyeon commented 2 weeks ago

Explain the concept of coroutine channels in Kotlin.

코루틴끼리의 통신을 위한 기본적인 방법으로 공유책장으로 비유하여 설명할 수 있다. 채널에는 send, receive 중단 함수가 있는데 send는 공유책장에 책이 가득 채워져 있을 때(채널의 용량이 가득 찼을 때) 중단되고, receive는 공유책장에 책이 없을 때(채널에 원소가 없을 때) 중단된다.

sujin9 commented 2 weeks ago

Explain the role of the asFlow extension function in Kotlin Coroutines.

s9hn commented 2 weeks ago

Q: What is the purpose of the StateFlow in Kotlin Coroutines?

hyemdooly commented 2 weeks ago

Q: Explain the concept of coroutine flow operators in Kotlin.

no1msh commented 2 weeks ago

What is the purpose of the launchIn and collectAsState functions in combination with Jetpack Compose?

collectAsState는 composable 내에서 flow를 상태로 변환하여 관찰하고 재구성을 트리거하는 데 사용되며, launchIn은 특정 코루틴 스코프에서 flow 수집을 시작하는 데 사용됩니다. 주로 ViewModel에서 stateFlow를 두고 launchIn으로 viewModelScope에서 수집하도록 하고 composable 함수에선 collectAsState로 구독하는 형태로 구현합니다.

krrong commented 2 weeks ago

Q: How does Kotlin Coroutines handle backpressure in flow-based programming?

Choisehyeon commented 2 weeks ago

Q: How do you handle exceptions in a coroutine flow in Kotlin?

flow에서 예외처리는 catch, retry, retryWhen을 사용하여 할 수 있다.

sujin9 commented 2 weeks ago

Q: Explain the difference between cold and hot flows in Kotlin Coroutines.

s9hn commented 2 weeks ago

Q: How can you implement a timeout for a coroutine flow in Kotlin?

A: Timeout for a coroutine flow can be implemented using the onTimeout operator. This operator allows you to specify a maximum duration for the flow to complete, and if the flow doesn't complete within that duration, it will be cancelled.

hyemdooly commented 2 weeks ago

StateFlow와 SharedFlow의 차이점 설명

no1msh commented 2 weeks ago

StateFlow와 LiveData의 차이점 설명 (값을 비교하는 로직의 차이점)

둘 모두 데이터의 상태를 관리하고 구독하여 UI를 알아서 업데이트되게 사용할 수 있지만 다음과 같은 차이점이 있습니다.

krrong commented 2 weeks ago

callbackFlow와 channelFlow 비교하여 설명

Choisehyeon commented 2 weeks ago

Flow에서 Buffer가 무엇이고 역할이 무엇인지 설명

flow의 collect를 활용하면 하나의 Coroutine에서 발행과 소비가 같이 일어나기 때문에 데이터를 다 소비한 후 다음 데이터가 발행된다. 발행과 소비에 모두 시간이 오래걸린다면 이는 매우 비효율적이다. 이를 방지하기 위해 buffer를 활용하여 발행과 소비를 위한 코루틴을 분리할 수 있다.

buffer 데이터 스트림에서 생산자와 소비자 간의 처리 속도 차이를 조정하고, 백프레셔를 완화하며, 비동기 처리를 가능하게 하는 중요한 도구이다.

sujin9 commented 2 weeks ago

combine, zip 연산자의 목적

s9hn commented 2 weeks ago

collect와 onEach의 차이

hyemdooly commented 2 weeks ago

flowOn이 무엇이고 사용 목적이 무엇인지

no1msh commented 2 weeks ago

cold flow를 사용했던 경험을 말씀해주세요.

Room을 통해 cold flow를 사용한 경험이 있습니다. Room은 flow를 지원하여 DAO 객체의 함수 반환값으로 flow를 사용할 수 있습니다. 저는 Room이 가진 데이터가 변경됨을 감지하여 UI를 자동적으로 갱신하는 로직을 구현하기 위해서 cold flow를 사용하여 구현하였습니다.

krrong commented 2 weeks ago

sequence와 flow의 차이가 뭔가요?

Choisehyeon commented 2 weeks ago

stateIn에는 어떤 파라미터가 있으며, 각각의 역할은 무엇인가요?

scope, started, initialValue

sujin9 commented 2 weeks ago

flow의 map 함수를 직접 구현하려면 어떻게 하실건가요?

s9hn commented 2 weeks ago

채널의 4가지 타입엔 어떤 것들이 있고 각각 간단한 설명을 해주실 수 있나요?

hyemdooly commented 2 weeks ago

flow의 최종 연산 함수는 무엇이 있을까요?

no1msh commented 2 weeks ago

Kotlin 코루틴에서 "debounce"의 역할은 무엇이며 성능을 최적화하는 데 어떻게 사용할 수 있습니까?

debounce는 인자로 받은 시간동안 이벤트가 발생하지 않으면 마지막 이벤트를 전달하는 함수입니다. 이러한 특성을 이용하여 검색창에 문자를 입력할 때마다 검색하지 않고 일정 시간이 지나야 검색하게끔 성능을 최적화 할 수 있습니다.

krrong commented 2 weeks ago

Kotlin 코루틴에서 "scan" 및 "fold" 작업의 역할을 설명하십시오.

Choisehyeon commented 2 weeks ago

Kotlin 코루틴을 사용하여 스로틀링 메커니즘을 어떻게 구현할 수 있습니까?

Throttle

동작 방식

throttleFirst, throttleLast도 개발자가 직접 구현하여야 한다. 코틀린에서는 코루틴과 Flow를 사용하여 손쉽게 쓰로틀링 매커니즘을 구현할 수 있다.

구현

sujin9 commented 2 weeks ago

Flow 변환에서 "emit" 및 "emitAll"의 역할을 설명하십시오.

s9hn commented 2 weeks ago

플로우의 "flatMapConcat", "flatMapMerge" 및 "flatMapLatest"는 무엇이며 서로 어떻게 다릅니까?

hyemdooly commented 2 weeks ago

코틀린에서 flow를 어떻게 생성하나요? flowOf와 asFlow 함수의 차이점에 대해서 설명해주세요.