Skip to content

Commit 1e07ccc

Browse files
Merge pull request #1231 from benjchristensen/682-share
Operator Alias: Share
2 parents 3d77dc9 + b42b4ac commit 1e07ccc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5324,6 +5324,23 @@ public final Observable<T> serialize() {
53245324
return lift(new OperatorSerialize<T>());
53255325
}
53265326

5327+
/**
5328+
* Returns a new {@link Observable} that multicasts (shares) the original {@link Observable}.
5329+
* As long as there is more than 1 {@link Subscriber} this {@link Observable} will be subscribed and emitting data.
5330+
* When all subscribers have unsubscribed it will unsubscribe from the source {@link Observable}.
5331+
* <p>
5332+
* This is an alias for {@link #publish().refCount()}.
5333+
* <p>
5334+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/publishConnect.png">
5335+
*
5336+
* @return a {@link Observable} that upon connection causes the source Observable to emit items
5337+
* to its {@link Observer}s
5338+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Connectable-Observable-Operators#wiki-observablepublish-and-observablemulticast">RxJava Wiki: publish()</a>
5339+
*/
5340+
public final Observable<T> share() {
5341+
return publish().refCount();
5342+
}
5343+
53275344
/**
53285345
* If the source Observable completes after emitting a single item, return an Observable that emits that
53295346
* item. If the source Observable emits more than one item or no items, throw an {@code NoSuchElementException}.

0 commit comments

Comments
 (0)