ROOM + Coroutine Flow - 5 (Flow)
코루틴 Flow를 잠깐 보고 갔는데, 이 친구가 뭐인지 한번 보고 가겠습니다.
간단하게 Flow Collect 기능을 통해서 데이터를 가져오는 것 말고 다양한 기능을 한번 보고 가겠습니다.
코루틴 공식 문서를 보면 아래와 같이 나와 있습니다.
A suspending function asynchronously returns a single value, but how can we return multiple asynchronously computed values? This is where Kotlin Flows come in.
single value는 suspension function 을 통해서 return 할 수 있는데, multiple values는 어떻게 할꺼냐? 이건 Flow를 이용해서 할 수 있다.
즉 아래에서 사용법들을 볼텐데, 데이터 스트림을 핸들링할 수 있다 라고 생각하면 되는데, RxJava를 사용해보신 분이 있다면, 유사하다고 느끼실 수도 있을 것 같습니다.
물론 여기에 대해서도 여러 사람이 올린 글이 있습니다.
여기에 대한 해답을 Flow 공식 문서 한번 살펴보겠습니다.
For those who are familiar with Reactive Streams or reactive frameworks such as RxJava and project Reactor, design of the Flow may look very familiar.
Indeed, its design was inspired by Reactive Streams and its various implementations. But Flow main goal is to have as simple design as possible, be Kotlin and suspension friendly and respect structured concurrency. Achieving this goal would be impossible without reactive pioneers and their tremendous work. You can read the complete story in Reactive Streams and Kotlin Flows article.
Rx에 대해서 영향을 많이 받았다. 라고 나옵니다.
그럼 여기까지 하고 Flow의 사용법을 잠시 보고 넘어가겠습니다.
- 참조
https://kotlinlang.org/docs/flow.html#launching-flow
Asynchronous Flow | Kotlin
kotlinlang.org
코루틴 공식 가이드 자세히 읽기 — Part 9-A
Asynchronous Flow
myungpyo.medium.com