|
13 | 13 |
|
14 | 14 | package io.reactivex.flowables;
|
15 | 15 |
|
16 |
| -import io.reactivex.annotations.NonNull; |
| 16 | +import java.util.concurrent.TimeUnit; |
| 17 | + |
17 | 18 | import org.reactivestreams.Subscriber;
|
18 | 19 |
|
19 |
| -import io.reactivex.Flowable; |
| 20 | +import io.reactivex.*; |
| 21 | +import io.reactivex.annotations.*; |
20 | 22 | import io.reactivex.disposables.Disposable;
|
21 | 23 | import io.reactivex.functions.Consumer;
|
22 |
| -import io.reactivex.internal.functions.Functions; |
| 24 | +import io.reactivex.internal.functions.*; |
23 | 25 | import io.reactivex.internal.operators.flowable.*;
|
24 | 26 | import io.reactivex.internal.util.ConnectConsumer;
|
25 | 27 | import io.reactivex.plugins.RxJavaPlugins;
|
| 28 | +import io.reactivex.schedulers.Schedulers; |
26 | 29 |
|
27 | 30 | /**
|
28 | 31 | * A {@code ConnectableFlowable} resembles an ordinary {@link Flowable}, except that it does not begin
|
@@ -68,15 +71,154 @@ public final Disposable connect() {
|
68 | 71 | /**
|
69 | 72 | * Returns a {@code Flowable} that stays connected to this {@code ConnectableFlowable} as long as there
|
70 | 73 | * is at least one subscription to this {@code ConnectableFlowable}.
|
71 |
| - * |
| 74 | + * <dl> |
| 75 | + * <dt><b>Backpressure:</b></dt> |
| 76 | + * <dd>The operator itself doesn't interfere with backpressure which is determined by the upstream |
| 77 | + * {@code ConnectableFlowable}'s backpressure behavior.</dd> |
| 78 | + * <dt><b>Scheduler:</b></dt> |
| 79 | + * <dd>This {@code refCount} overload does not operate on any particular {@link Scheduler}.</dd> |
| 80 | + * </dl> |
72 | 81 | * @return a {@link Flowable}
|
73 | 82 | * @see <a href="http://reactivex.io/documentation/operators/refcount.html">ReactiveX documentation: RefCount</a>
|
| 83 | + * @see #refCount(int) |
| 84 | + * @see #refCount(long, TimeUnit) |
| 85 | + * @see #refCount(int, long, TimeUnit) |
74 | 86 | */
|
75 | 87 | @NonNull
|
| 88 | + @CheckReturnValue |
| 89 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 90 | + @BackpressureSupport(BackpressureKind.PASS_THROUGH) |
76 | 91 | public Flowable<T> refCount() {
|
77 | 92 | return RxJavaPlugins.onAssembly(new FlowableRefCount<T>(this));
|
78 | 93 | }
|
79 | 94 |
|
| 95 | + /** |
| 96 | + * Connects to the upstream {@code ConnectableFlowable} if the number of subscribed |
| 97 | + * subscriber reaches the specified count and disconnect if all subscribers have unsubscribed. |
| 98 | + * <dl> |
| 99 | + * <dt><b>Backpressure:</b></dt> |
| 100 | + * <dd>The operator itself doesn't interfere with backpressure which is determined by the upstream |
| 101 | + * {@code ConnectableFlowable}'s backpressure behavior.</dd> |
| 102 | + * <dt><b>Scheduler:</b></dt> |
| 103 | + * <dd>This {@code refCount} overload does not operate on any particular {@link Scheduler}.</dd> |
| 104 | + * </dl> |
| 105 | + * @param subscriberCount the number of subscribers required to connect to the upstream |
| 106 | + * @return the new Flowable instance |
| 107 | + * @since 2.1.14 - experimental |
| 108 | + */ |
| 109 | + @CheckReturnValue |
| 110 | + @Experimental |
| 111 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 112 | + @BackpressureSupport(BackpressureKind.PASS_THROUGH) |
| 113 | + public final Flowable<T> refCount(int subscriberCount) { |
| 114 | + return refCount(subscriberCount, 0, TimeUnit.NANOSECONDS, Schedulers.trampoline()); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Connects to the upstream {@code ConnectableFlowable} if the number of subscribed |
| 119 | + * subscriber reaches 1 and disconnect after the specified |
| 120 | + * timeout if all subscribers have unsubscribed. |
| 121 | + * <dl> |
| 122 | + * <dt><b>Backpressure:</b></dt> |
| 123 | + * <dd>The operator itself doesn't interfere with backpressure which is determined by the upstream |
| 124 | + * {@code ConnectableFlowable}'s backpressure behavior.</dd> |
| 125 | + * <dt><b>Scheduler:</b></dt> |
| 126 | + * <dd>This {@code refCount} overload operates on the {@code computation} {@link Scheduler}.</dd> |
| 127 | + * </dl> |
| 128 | + * @param timeout the time to wait before disconnecting after all subscribers unsubscribed |
| 129 | + * @param unit the time unit of the timeout |
| 130 | + * @return the new Flowable instance |
| 131 | + * @since 2.1.14 - experimental |
| 132 | + * @see #refCount(long, TimeUnit, Scheduler) |
| 133 | + */ |
| 134 | + @CheckReturnValue |
| 135 | + @Experimental |
| 136 | + @SchedulerSupport(SchedulerSupport.COMPUTATION) |
| 137 | + @BackpressureSupport(BackpressureKind.PASS_THROUGH) |
| 138 | + public final Flowable<T> refCount(long timeout, TimeUnit unit) { |
| 139 | + return refCount(1, timeout, unit, Schedulers.computation()); |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Connects to the upstream {@code ConnectableFlowable} if the number of subscribed |
| 144 | + * subscriber reaches 1 and disconnect after the specified |
| 145 | + * timeout if all subscribers have unsubscribed. |
| 146 | + * <dl> |
| 147 | + * <dt><b>Backpressure:</b></dt> |
| 148 | + * <dd>The operator itself doesn't interfere with backpressure which is determined by the upstream |
| 149 | + * {@code ConnectableFlowable}'s backpressure behavior.</dd> |
| 150 | + * <dt><b>Scheduler:</b></dt> |
| 151 | + * <dd>This {@code refCount} overload operates on the specified {@link Scheduler}.</dd> |
| 152 | + * </dl> |
| 153 | + * @param timeout the time to wait before disconnecting after all subscribers unsubscribed |
| 154 | + * @param unit the time unit of the timeout |
| 155 | + * @param scheduler the target scheduler to wait on before disconnecting |
| 156 | + * @return the new Flowable instance |
| 157 | + * @since 2.1.14 - experimental |
| 158 | + */ |
| 159 | + @CheckReturnValue |
| 160 | + @Experimental |
| 161 | + @SchedulerSupport(SchedulerSupport.CUSTOM) |
| 162 | + @BackpressureSupport(BackpressureKind.PASS_THROUGH) |
| 163 | + public final Flowable<T> refCount(long timeout, TimeUnit unit, Scheduler scheduler) { |
| 164 | + return refCount(1, timeout, unit, scheduler); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Connects to the upstream {@code ConnectableFlowable} if the number of subscribed |
| 169 | + * subscriber reaches the specified count and disconnect after the specified |
| 170 | + * timeout if all subscribers have unsubscribed. |
| 171 | + * <dl> |
| 172 | + * <dt><b>Backpressure:</b></dt> |
| 173 | + * <dd>The operator itself doesn't interfere with backpressure which is determined by the upstream |
| 174 | + * {@code ConnectableFlowable}'s backpressure behavior.</dd> |
| 175 | + * <dt><b>Scheduler:</b></dt> |
| 176 | + * <dd>This {@code refCount} overload operates on the {@code computation} {@link Scheduler}.</dd> |
| 177 | + * </dl> |
| 178 | + * @param subscriberCount the number of subscribers required to connect to the upstream |
| 179 | + * @param timeout the time to wait before disconnecting after all subscribers unsubscribed |
| 180 | + * @param unit the time unit of the timeout |
| 181 | + * @return the new Flowable instance |
| 182 | + * @since 2.1.14 - experimental |
| 183 | + * @see #refCount(int, long, TimeUnit, Scheduler) |
| 184 | + */ |
| 185 | + @CheckReturnValue |
| 186 | + @Experimental |
| 187 | + @SchedulerSupport(SchedulerSupport.COMPUTATION) |
| 188 | + @BackpressureSupport(BackpressureKind.PASS_THROUGH) |
| 189 | + public final Flowable<T> refCount(int subscriberCount, long timeout, TimeUnit unit) { |
| 190 | + return refCount(subscriberCount, timeout, unit, Schedulers.computation()); |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * Connects to the upstream {@code ConnectableFlowable} if the number of subscribed |
| 195 | + * subscriber reaches the specified count and disconnect after the specified |
| 196 | + * timeout if all subscribers have unsubscribed. |
| 197 | + * <dl> |
| 198 | + * <dt><b>Backpressure:</b></dt> |
| 199 | + * <dd>The operator itself doesn't interfere with backpressure which is determined by the upstream |
| 200 | + * {@code ConnectableFlowable}'s backpressure behavior.</dd> |
| 201 | + * <dt><b>Scheduler:</b></dt> |
| 202 | + * <dd>This {@code refCount} overload operates on the specified {@link Scheduler}.</dd> |
| 203 | + * </dl> |
| 204 | + * @param subscriberCount the number of subscribers required to connect to the upstream |
| 205 | + * @param timeout the time to wait before disconnecting after all subscribers unsubscribed |
| 206 | + * @param unit the time unit of the timeout |
| 207 | + * @param scheduler the target scheduler to wait on before disconnecting |
| 208 | + * @return the new Flowable instance |
| 209 | + * @since 2.1.14 - experimental |
| 210 | + */ |
| 211 | + @CheckReturnValue |
| 212 | + @Experimental |
| 213 | + @SchedulerSupport(SchedulerSupport.CUSTOM) |
| 214 | + @BackpressureSupport(BackpressureKind.PASS_THROUGH) |
| 215 | + public final Flowable<T> refCount(int subscriberCount, long timeout, TimeUnit unit, Scheduler scheduler) { |
| 216 | + ObjectHelper.verifyPositive(subscriberCount, "subscriberCount"); |
| 217 | + ObjectHelper.requireNonNull(unit, "unit is null"); |
| 218 | + ObjectHelper.requireNonNull(scheduler, "scheduler is null"); |
| 219 | + return RxJavaPlugins.onAssembly(new FlowableRefCount<T>(this, subscriberCount, timeout, unit, scheduler)); |
| 220 | + } |
| 221 | + |
80 | 222 | /**
|
81 | 223 | * Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable
|
82 | 224 | * when the first Subscriber subscribes.
|
|
0 commit comments