Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed image link and added java examples for Connectable Observable operators #6997

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions docs/Connectable-Observable-Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@ This section explains the [`ConnectableObservable`](http://reactivex.io/RxJava/j

A Connectable Observable resembles an ordinary Observable, except that it does not begin emitting items when it is subscribed to, but only when its `connect()` method is called. In this way you can wait for all intended Subscribers to subscribe to the Observable before the Observable begins emitting items.

<img src="/ReactiveX/RxJava/wiki/images/rx-operators/publishConnect.v3.png" width="640" height="510" />
<img src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/publishConnect.v3.png" width="640" height="510" />

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:**
```groovy
def firstMillion = Observable.range( 1, 1000000 ).sample(7, java.util.concurrent.TimeUnit.MILLISECONDS);
```java
Observable firstMillion = Observable.range(1, 1000000).sample(7, java.util.concurrent.TimeUnit.MILLISECONDS);

firstMillion.subscribe(
{ println("Subscriber #1:" + it); }, // onNext
{ println("Error: " + it.getMessage()); }, // onError
{ println("Sequence #1 complete"); } // onCompleted
);

firstMillion.subscribe(
{ println("Subscriber #2:" + it); }, // onNext
{ println("Error: " + it.getMessage()); }, // onError
{ println("Sequence #2 complete"); } // onCompleted
);
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
);
```
```
Subscriber #1:211128
Expand All @@ -40,20 +37,18 @@ Subscriber #2:826996
Sequence #2 complete
```
**Example #2:**
```groovy
def firstMillion = Observable.range( 1, 1000000 ).sample(7, java.util.concurrent.TimeUnit.MILLISECONDS).publish();
```java
ConnectableObservable firstMillion = Observable.range(1, 1000000).sample(7, java.util.concurrent.TimeUnit.MILLISECONDS).publish();

firstMillion.subscribe(
{ println("Subscriber #1:" + it); }, // onNext
{ println("Error: " + it.getMessage()); }, // onError
{ println("Sequence #1 complete"); } // onCompleted
);
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(
{ println("Subscriber #2:" + it); }, // onNext
{ println("Error: " + it.getMessage()); }, // onError
{ println("Sequence #2 complete"); } // onCompleted
);
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();
```
Expand Down
24 changes: 12 additions & 12 deletions docs/Getting-Started.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
## Getting Binaries

You can find binaries and dependency information for Maven, Ivy, Gradle, SBT, and others at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A"io.reactivex.rxjava2"%20AND%20"rxjava2").
You can find binaries and dependency information for Maven, Ivy, Gradle, SBT, and others at [http://search.maven.org](https://search.maven.org/search?q=g:io.reactivex.rxjava3%20AND%20rxjava).

Example for Maven:

```xml
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.0</version>
<version>3.0.4</version>
</dependency>
```
and for Ivy:

```xml
<dependency org="io.reactivex.rxjava2" name="rxjava" rev="2.2.0" />
<dependency org="io.reactivex.rxjava3" name="rxjava" rev="3.0.4" />
```

and for SBT:

```scala
libraryDependencies += "io.reactivex" %% "rxscala" % "0.26.5"

libraryDependencies += "io.reactivex.rxjava2" % "rxjava" % "2.2.0"
libraryDependencies += "io.reactivex.rxjava3" % "rxjava" % "3.0.4"
```

and for Gradle:
```groovy
compile 'io.reactivex.rxjava2:rxjava:2.2.0'
compile 'io.reactivex.rxjava3:rxjava:3.0.4'
```

If you need to download the jars instead of using a build system, create a Maven `pom` file like this with the desired version:
Expand All @@ -38,17 +38,17 @@ If you need to download the jars instead of using a build system, create a Maven
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.reactivex.rxjava2</groupId>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.0</version>
<version>3.0.4</version>
<name>RxJava</name>
<description>Reactive Extensions for Java</description>
<url>https://github.com/ReactiveX/RxJava</url>
<dependencies>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.0</version>
<version>3.0.4</version>
</dependency>
</dependencies>
</project>
Expand All @@ -66,15 +66,15 @@ You need Java 6 or later.

### Snapshots

Snapshots are available via [JFrog](https://oss.jfrog.org/libs-snapshot/io/reactivex/rxjava2/rxjava/):
Snapshots are available via [JFrog](https://oss.jfrog.org/libs-snapshot/io/reactivex/rxjava3/rxjava/):

```groovy
repositories {
maven { url 'https://oss.jfrog.org/libs-snapshot' }
}

dependencies {
compile 'io.reactivex.rxjava2:rxjava:2.2.0-SNAPSHOT'
compile 'io.reactivex.rxjava3:rxjava:3.0.4'
}
```

Expand Down