일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- stable-diffusion-webui local 네트워크에서 접속
- supabase storage feature not enabled for this tenant
- 주 4일 근무제 경험담
- invite user for supabase project
- DT_TOOLCHAIN_DIR cannot be used
- Android apple login identifier
- supabase edge function deploy error supabaseurl is required
- Spring LocalDateTime response array
- 소개팅앱 만들기
- Spring google SMTP settings
- 주 4일 근무제
- 소개팅앱 만들기 flutter
- Supabase edge function insert data
- stable-diffusion-webui local 접속
- Stomp socket connection event
- Firebase authentication android apple login setting
- supabase edge function deploy error
- Firebase authentication android apple login
- supabase storage public url not working
- no such module '__ObjC'
- 로컬 서버 접속
- Android apple login
- Supabase edge function
- Android apple login 인증서 설정
- Stomp user connection event
- Spring boot swagger blank screen
- 주 4일 근무제 log
- 소개팅앱 만들기 stomp
- Firebase authentication apple login
- Firebase authentication apple login 최신
- Today
- Total
꿀맛코딩
What is ConnectableObservable? 본문
ConnectableObservable 이란?
Hot Observable 과 Cold Observable 둘다 사용 가능한 Observable 로서
기능은 다음과 같다.
1. Cold Observable < - > Hot Observable 변환 가능
2. 한개의 Observable에 여러개의 구독을 할수 있으며,
기존의 Cold Observable 처럼 구독시 처음부터 아이템을 배출 하는게 아니라
이전에 호출된 모든 Observer 를 연결 하고 모든 Observer 에게 단일 푸쉬를 전달한다.
fun simpleConnectableObservable() {
val connectableObservable = listOf("Stream1", "Stream2", "Stream3", "Stream4").toObservable().publish() (1)
connectableObservable.subscribe{ println("SubScription 1: $it") } (2)
connectableObservable.map { it.reversed()}.subscribe{ println("SubScription 2 $it") } (3)
connectableObservable.connect() (4)
connectableObservable.subscribe{ println("Subscription 3: $it") } (5)
}
코드를 차근 차근 살펴 보자
(1) list를 toObservable을 이용하여 Observable 을 생성하고,
publish 메서드를 이용하여 Cold Observerble 을 ConnectableObservable로 변환 했다.
(2) connectableObservable 을 구독하고 요소들을 print 할수 있게 했다.
(3) map 을 이용하여 요소들을 역으로 바꾸고 print 할수 있게 했다.
(4) connect를 이용하여 이전에 Subsription한 모든 Observer들 에게 데이터를 배출하기 시작한다.
(5) connectableObservable 을 구독하고 요소들을 print 할수 있게 했다.
결과
그림 1을 보면서 설명 하겠습니다.
결과물을 보면
(2) Observer 가 출력이 되고
다음으로 (3) Observer 가 String 을 역으로 출력을 하는데
(4) 번 Observer 는 동작을 하지 않았다.
이유는 ConnectableObservable은 (4) 을 한순간에 이전에 자신을 Subscribe 한 Observer 들에게
이미 배출 이 끝낫으므로 (5) Observer 는 데이터를 받지 못한다.
이전의 from 이나 just 같은 경우는 subscribe 하면, 처음부터 데이터를 배출 했지만,
ConnectableObservable은 기존 배출을 유지하며 Observer 들에게 데이터를 전달한다.
'공부방 > RxKotlin' 카테고리의 다른 글
defualtIfEmpty and switchIfEmpty (0) | 2019.07.29 |
---|---|
What is BackPressure? (BackPressure 란?) (0) | 2019.07.25 |
observable.from and observable.just (0) | 2019.07.23 |
cold observable and hot observable (0) | 2019.07.23 |
What is Observable? (0) | 2019.07.23 |