Skip to content

Commit 5c0a955

Browse files
committed
add javadocs to describe SerializedSubject class
(also correct error in javadoc comments for OperatorDoOnSubscribe, for what it's worth)
1 parent af43408 commit 5c0a955

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/rx/internal/operators/OperatorDoOnSubscribe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class OperatorDoOnSubscribe<T> implements Operator<T, T> {
2828

2929
/**
3030
* Constructs an instance of the operator with the callback that gets invoked when the modified Observable is subscribed
31-
* @param unsubscribe The action that gets invoked when the modified {@link rx.Observable} is subscribed
31+
* @param subscribe the action that gets invoked when the modified {@link rx.Observable} is subscribed
3232
*/
3333
public OperatorDoOnSubscribe(Action0 subscribe) {
3434
this.subscribe = subscribe;

src/main/java/rx/subjects/SerializedSubject.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@
1818
import rx.Subscriber;
1919
import rx.observers.SerializedObserver;
2020

21+
/**
22+
* Wraps a {@link Subject} so that it is safe to call its various {@code on} methods from different threads.
23+
* <p>
24+
* When you use an ordinary {@link Subject} as a {@link Subscriber}, you must take care not to call its
25+
* {@link Subscriber#onNext} method (or its other {@code on} methods) from multiple threads, as this could lead
26+
* to non-serialized calls, which violates the Observable contract and creates an ambiguity in the resulting
27+
* Subject.
28+
* <p>
29+
* To protect a {@code Subject} from this danger, you can convert it into a {@code SerializedSubject} with code
30+
* like the following:
31+
* <p><pre>{@code
32+
* mySafeSubject = new SerializedSubject( myUnsafeSubject );
33+
* }</pre>
34+
*/
2135
public class SerializedSubject<T, R> extends Subject<T, R> {
2236
private final SerializedObserver<T> observer;
2337

0 commit comments

Comments
 (0)