Skip to content

Commit ec40a5e

Browse files
authored
2.x: improve autoConnect() Javadoc + add its marble (#5756)
1 parent 564c3dc commit ec40a5e

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

src/main/java/io/reactivex/flowables/ConnectableFlowable.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,45 @@ public Flowable<T> refCount() {
7878
}
7979

8080
/**
81-
* Returns a Flowable that automatically connects to this ConnectableFlowable
81+
* Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable
8282
* when the first Subscriber subscribes.
83+
* <p>
84+
* <img width="640" height="392" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/autoConnect.f.png" alt="">
85+
* <p>
86+
* The connection happens after the first subscription and happens at most once
87+
* during the lifetime of the returned Flowable. If this ConnectableFlowable
88+
* terminates, the connection is never renewed, no matter how Subscribers come
89+
* and go. Use {@link #refCount()} to renew a connection or dispose an active
90+
* connection when all {@code Subscriber}s have cancelled their {@code Subscription}s.
91+
* <p>
92+
* This overload does not allow disconnecting the connection established via
93+
* {@link #connect(Consumer)}. Use the {@link #autoConnect(int, Consumer)} overload
94+
* to gain access to the {@code Disposable} representing the only connection.
8395
*
8496
* @return a Flowable that automatically connects to this ConnectableFlowable
8597
* when the first Subscriber subscribes
98+
* @see #refCount()
99+
* @see #autoConnect(int, Consumer)
86100
*/
87101
@NonNull
88102
public Flowable<T> autoConnect() {
89103
return autoConnect(1);
90104
}
91105
/**
92-
* Returns a Flowable that automatically connects to this ConnectableFlowable
106+
* Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable
93107
* when the specified number of Subscribers subscribe to it.
108+
* <p>
109+
* <img width="640" height="392" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/autoConnect.f.png" alt="">
110+
* <p>
111+
* The connection happens after the given number of subscriptions and happens at most once
112+
* during the lifetime of the returned Flowable. If this ConnectableFlowable
113+
* terminates, the connection is never renewed, no matter how Subscribers come
114+
* and go. Use {@link #refCount()} to renew a connection or dispose an active
115+
* connection when all {@code Subscriber}s have cancelled their {@code Subscription}s.
116+
* <p>
117+
* This overload does not allow disconnecting the connection established via
118+
* {@link #connect(Consumer)}. Use the {@link #autoConnect(int, Consumer)} overload
119+
* to gain access to the {@code Disposable} representing the only connection.
94120
*
95121
* @param numberOfSubscribers the number of subscribers to await before calling connect
96122
* on the ConnectableFlowable. A non-positive value indicates
@@ -104,9 +130,17 @@ public Flowable<T> autoConnect(int numberOfSubscribers) {
104130
}
105131

106132
/**
107-
* Returns a Flowable that automatically connects to this ConnectableFlowable
133+
* Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable
108134
* when the specified number of Subscribers subscribe to it and calls the
109135
* specified callback with the Subscription associated with the established connection.
136+
* <p>
137+
* <img width="640" height="392" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/autoConnect.f.png" alt="">
138+
* <p>
139+
* The connection happens after the given number of subscriptions and happens at most once
140+
* during the lifetime of the returned Flowable. If this ConnectableFlowable
141+
* terminates, the connection is never renewed, no matter how Subscribers come
142+
* and go. Use {@link #refCount()} to renew a connection or dispose an active
143+
* connection when all {@code Subscriber}s have cancelled their {@code Subscription}s.
110144
*
111145
* @param numberOfSubscribers the number of subscribers to await before calling connect
112146
* on the ConnectableFlowable. A non-positive value indicates

src/main/java/io/reactivex/observables/ConnectableObservable.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,20 @@ public Observable<T> refCount() {
7777
}
7878

7979
/**
80-
* Returns an Observable that automatically connects to this ConnectableObservable
80+
* Returns an Observable that automatically connects (at most once) to this ConnectableObservable
8181
* when the first Observer subscribes.
82+
* <p>
83+
* <img width="640" height="348" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/autoConnect.o.png" alt="">
84+
* <p>
85+
* The connection happens after the first subscription and happens at most once
86+
* during the lifetime of the returned Observable. If this ConnectableObservable
87+
* terminates, the connection is never renewed, no matter how Observers come
88+
* and go. Use {@link #refCount()} to renew a connection or dispose an active
89+
* connection when all {@code Observers}s have disposed their {@code Disposable}s.
90+
* <p>
91+
* This overload does not allow disconnecting the connection established via
92+
* {@link #connect(Consumer)}. Use the {@link #autoConnect(int, Consumer)} overload
93+
* to gain access to the {@code Disposable} representing the only connection.
8294
*
8395
* @return an Observable that automatically connects to this ConnectableObservable
8496
* when the first Observer subscribes
@@ -89,8 +101,20 @@ public Observable<T> autoConnect() {
89101
}
90102

91103
/**
92-
* Returns an Observable that automatically connects to this ConnectableObservable
104+
* Returns an Observable that automatically connects (at most once) to this ConnectableObservable
93105
* when the specified number of Observers subscribe to it.
106+
* <p>
107+
* <img width="640" height="348" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/autoConnect.o.png" alt="">
108+
* <p>
109+
* The connection happens after the given number of subscriptions and happens at most once
110+
* during the lifetime of the returned Observable. If this ConnectableObservable
111+
* terminates, the connection is never renewed, no matter how Observers come
112+
* and go. Use {@link #refCount()} to renew a connection or dispose an active
113+
* connection when all {@code Observers}s have disposed their {@code Disposable}s.
114+
* <p>
115+
* This overload does not allow disconnecting the connection established via
116+
* {@link #connect(Consumer)}. Use the {@link #autoConnect(int, Consumer)} overload
117+
* to gain access to the {@code Disposable} representing the only connection.
94118
*
95119
* @param numberOfSubscribers the number of subscribers to await before calling connect
96120
* on the ConnectableObservable. A non-positive value indicates
@@ -104,9 +128,17 @@ public Observable<T> autoConnect(int numberOfSubscribers) {
104128
}
105129

106130
/**
107-
* Returns an Observable that automatically connects to this ConnectableObservable
131+
* Returns an Observable that automatically connects (at most once) to this ConnectableObservable
108132
* when the specified number of Subscribers subscribe to it and calls the
109133
* specified callback with the Subscription associated with the established connection.
134+
* <p>
135+
* <img width="640" height="348" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/autoConnect.o.png" alt="">
136+
* <p>
137+
* The connection happens after the given number of subscriptions and happens at most once
138+
* during the lifetime of the returned Observable. If this ConnectableObservable
139+
* terminates, the connection is never renewed, no matter how Observers come
140+
* and go. Use {@link #refCount()} to renew a connection or dispose an active
141+
* connection when all {@code Observers}s have disposed their {@code Disposable}s.
110142
*
111143
* @param numberOfSubscribers the number of subscribers to await before calling connect
112144
* on the ConnectableObservable. A non-positive value indicates

0 commit comments

Comments
 (0)