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

2.x: fix/clarify the Observable class' javadoc #5432

Merged
merged 2 commits into from
Jun 23, 2017
Merged
Changes from 1 commit
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
55 changes: 47 additions & 8 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import io.reactivex.schedulers.*;

/**
* The Observable class that is designed similar to the Reactive-Streams Pattern, minus the backpressure,
* and offers factory methods, intermediate operators and the ability to consume reactive dataflows.
* The Observable class is the non-backpressured, optionally multi-valued base reactive class that
* offers factory methods, intermediate operators and the ability to consume synchronous
* and/or asynchronous reactive dataflows.
* <p>
* Reactive-Streams operates with {@code ObservableSource}s which {@code Observable} extends. Many operators
* therefore accept general {@code ObservableSource}s directly and allow direct interoperation with other
* Reactive-Streams implementations.
* Many operators in the class accept {@code ObservableSource}(s), the base reactive interface
* for such non-backpressured flows, which {@code Observable} itself extends as well.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/extends/implements

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

* <p>
* The Observable's operators, by default, run with a buffer size of 128 elements (see {@link Flowable#bufferSize()},
* that can be overridden globally via the system parameter {@code rx2.buffer-size}. Most operators, however, have
Expand All @@ -49,11 +49,50 @@
* <p>
* <img width="640" height="317" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/legend.png" alt="">
* <p>
* For more information see the <a href="http://reactivex.io/documentation/ObservableSource.html">ReactiveX
* documentation</a>.
*
* The design of this class was derived from the
* <a href="https://github.com/reactive-streams/reactive-streams-jvm">Reactive-Streams design and specification</a>
* by removing any backpressure-related infrastructure and implementation detail, replacing the
* {@code org.reactivestreams.Subscription} with {@link Disposable} as the primary means to cancel
* a flow.
* <p>
* The {@code Observable} follows the protocol
* <pre><code>
* onSubscribe onNext* (onError | onComplete)?
Copy link
Collaborator

@vanniktech vanniktech Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe onNext(T)*?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters are omitted to avoid conflict with the regexp-like pattern

* </code></pre>
* where
* the stream can be disposed through the {@code Disposable} instance provided to consumers through
* {@code Observer.onSubscribe}.
* <p>
* Unlike the {@code Observable} of version 1.x, {@link #subscribe(Observer)} does not allow external cancellation
* of a subscription and the {@code Observer} instance is expected to expose such capability.
* <p>Example:
* <pre><code>
* Disposable d = Observable.just("Hello world!")
* .delay(1, TimeUnit.SECONDS)
* .subscribeWith(new DisposableObserver&lt;String>() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/>/&gt;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing > doesn't need escaping.

* &#64;Override public void onStart() {
* System.out.println("Start!");
* }
* &#64;Override public void onNext(Integer t) {
* System.out.println(t);
* }
* &#64;Override public void onError(Throwable t) {
* t.printStackTrace();
* }
* &#64;Override public void onComplete() {
* System.out.println("Done!");
* }
* });
*
* Thread.sleep(500);
* // the sequence now can be cancelled via dispose()
* d.dispose();
* </code></pre>
*
* @param <T>
* the type of the items emitted by the Observable
* @see Flowable
* @see io.reactivex.observers.DisposableObserver
*/
public abstract class Observable<T> implements ObservableSource<T> {

Expand Down