
RxJava 예외 처리 기본적으로 Observer의 onError 함수를 통해서 에러를 처리할 수 있습니다. onError로 에러를 처리하는 경우 스트림은 데이터 발행을 중단하며 Observer는 onComplete 호출을 하지 못합니다. fun onError() { Observable.create { emitter -> emitter.onNext("Message 1") emitter.onNext("Message 2") throw Exception("Something Wrong") }.subscribe({ println(it) }, { println("Error : $it") }) } Message 1 Message 2 Error : java.lang.Exception: Something Wrong Rx..

Subject(링크) Subject는 데이터 발행과 구독을 한번에 할 수 있는 클래스입니다. onNext, onError, onComplete 함수로 데이터를 발행할 수 있으며, subscribe 함수로 데이터 구독을 할 수 있습니다. fun subject() { val subject = PublishSubject.create() subject.subscribe { println(it) } subject.onNext(1) subject.onError(Exception()) subject.onComplete() } AsyncSubject Subject에서 마지막으로 발행한 데이터만 받아옵니다. 완료되기 전 발행한 데이터는 무시합니다. 만약 오류가 발생하면 아무 값도 발행하지 않고 오류를 보냅니다. fun ..

Scheduler Scheduler는 RxJava에서 어떤 쓰레드에서 실행될지 결정하는 역할을 합니다. 단순히 Observable를 만든다고 비동기 실행이 되는 것이 아닌, Scheduler를 적절히 사용해야 비동기로 실행할 수 있습니다. Scheduler를 사용하지 않은 경우 Observable를 만들지만 내부적으로 같은 쓰레드를 사용하기 때문에 순차적으로 실행된다. fun schedulerTest1() { Observable.create { Thread.sleep(1500L) it.onNext(100) }.subscribe { println("subscribe : $it") } println("Finish") Thread.sleep(3000L) } subscribe : 100 Finish Schedu..

Observable 데이터 소비와 상관없이 데이터를 계속 발행합니다. fun observableTest() { Observable.range(1, 10000) .doOnNext { println("emit : $it") } .observeOn(Schedulers.io()) .subscribe { Thread.sleep(100L) println("comsume : $it") } Thread.sleep(100000) } emit : 1 emit : 2 emit : 3 ... emit : 9998 emit : 9999 emit : 10000 comsume : 1 comsume : 2 comsume : 3 ... Flowable Flowable은 Observable과 다르게 Backpressure를 지원하며,..
Cold Observable Cold Observable은 Observable를 생성하고 Observer가 subscribe를 호출할 때 데이터 발행을 시작합니다. 즉, Observer가 없으면 데이터를 발행하지 않습니다. 다른말로 Lazy하게 데이터를 발행한다고 표현합니다. 일반적으로 One Time 질의(DB 조회, API 호출, File IO 등)에 사용하고, 원하는 시점에 요청하여 결과를 받아오는 작업에 쓰입니다. * 지금까지 예시로 사용했던 Single, Maybe 등이 Cold Observable에 속합니다. Hot Observable Cold와 반대로 Observable를 생성하면 Observer 유무의 상관없이 데이터를 발행합니다. 중간에 Observer가 등록되어 subscribe를 시작..

Operator 데이터 스트림을 쉽게 변형하기 위해 Operator를 사용합니다. Collections에서 제공하는 forEach, map 같은 Operator뿐만 아니라 Rx에서 추가적으로 제공하는 debounce, buffer 같은 함수들이 있습니다. https://reactivex.io/documentation/operators.html ReactiveX - Operators Introduction Each language-specific implementation of ReactiveX implements a set of operators. Although there is much overlap between implementations, there are also some operators th..

Observable RxJava의 가장 핵심적인 요소입니다. Observable은 데이터를 흐름에 맞게 만들어서 Observer에게 보내는 역할을 합니다. RxJava는 이벤트를 통한 Observer Pattern을 기반으로 만들어졌습니다. Observable 가장 기본적인 형태, N개의 데이터를 발행할 수 있습니다. onComplete를 통해 완료를 알릴 수 있으며 onError를 통해 에러를 처리할 수 있습니다. onComplete, onError가 호출되면 이후에 발행하는 onNext는 무시합니다. fun observable() { Observable.create { emitter -> emitter.onNext(1) emitter.onNext(2) emitter.onNext(3) emitter.o..

Reactive Programming 데이터의 흐름을 먼저 정의하고 데이터가 반영되었을 때 연관된 작업이 실행횐다. 즉, 이벤트에 반응하여 프로그램이 동작한다. 어떻게 이벤트를 반응할까? Observer 패턴 (이벤트 처리) Iterator 패턴 (이벤트 처리) Functional 프로그래밍 (이벤트 가공) RxJava https://reactivex.io/intro.html ReactiveX is a library for composing asynchronous and event-based programs by using observable sequences. It extends the observer pattern to support sequences of data and/or events and a..
- Total
- Today
- Yesterday
- ViewModelProvider
- 클린 코드
- Coroutine
- 클린코드
- Flowable
- ViewModelStoreOwner
- Exception
- Flutter
- Widget
- Android
- isActive
- commit
- ConcatAdapter.Config
- DSL
- viewmodel
- Kotlin
- ConcatAdapter
- 보이스카우트 규칙
- git
- null
- clean code
- observable
- 코루틴
- 연산자
- DART
- TDD
- CancellationException
- gradle
- rxjava
- 함수
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |