GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Connectable Observable Operators Connectable Observable Operators
akarnokd edited this page
This section explains the
A Connectable Observable resembles an ordinary Observable, except that it does not begin emitting items when it is subscribed to, but only when its
The following example code shows two Subscribers subscribing to the same Observable. In the first case, they subscribe to an ordinary Observable; in the second case, they subscribe to a Connectable Observable that only connects after both Subscribers subscribe. Note the difference in the output: Example #1: Observable firstMillion = Observable.range(1, 1000000).sample(7, java.util.concurrent.TimeUnit.MILLISECONDS); firstMillion.subscribe(next -> System.out.println("Subscriber #1: " + next), // onNext throwable -> System.out.println("Error: " + throwable), // onError () -> System.out.println("Sequence #1 complete") // onComplete ); firstMillion.subscribe(next -> System.out.println("Subscriber #2: " + next), // onNext throwable -> System.out.println("Error: " + throwable), // onError () -> System.out.println("Sequence #2 complete") // onComplete ); Example #2: ConnectableObservable firstMillion = Observable.range(1, 1000000).sample(7, java.util.concurrent.TimeUnit.MILLISECONDS).publish(); firstMillion.subscribe(next -> System.out.println("Subscriber #1: " + next), // onNext throwable -> System.out.println("Error: " + throwable), // onError () -> System.out.println("Sequence #1 complete") // onComplete ); firstMillion.subscribe(next -> System.out.println("Subscriber #2: " + next), // onNext throwable -> System.out.println("Error: " + throwable), // onError () -> System.out.println("Sequence #2 complete") // onComplete ); firstMillion.connect(); Copyright (c) 2016-present, RxJava Contributors. Clone this wiki locally |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |