/** * Connects to the upstream source when the given number of {@link org.reactivestreams.Subscriber} subscribes and disconnects * when all Subscribers cancelled or the upstream source completed. * * <p> * <img class="marble" src="doc-files/marbles/refCountWithMinSubscribers.svg" alt=""> * * @param minSubscribers the number of subscribers expected to subscribe before connection * * @return a reference counting {@link Flux} */ public final Flux<T> refCount(int minSubscribers) { return onAssembly(new FluxRefCount<>(this, minSubscribers)); }
/** * Connects to the upstream source when the given number of {@link org.reactivestreams.Subscriber} subscribes. * Disconnection can happen in two scenarios: when the upstream source completes (or errors) then * there is an immediate disconnection. However, when all subscribers have cancelled, * a <strong>deferred</strong> disconnection is scheduled. If any new subscriber comes * in during the {@code gracePeriod} that follows, the disconnection is cancelled. * * <p> * <img class="marble" src="doc-files/marbles/refCountWithMinSubscribersAndGracePeriod.svg" alt=""> * * @param minSubscribers the number of subscribers expected to subscribe before connection * @param gracePeriod the {@link Duration} for which to wait for new subscribers before actually * disconnecting when all subscribers have cancelled. * @param scheduler the {@link Scheduler} on which to run timeouts * * @return a reference counting {@link Flux} with a grace period for disconnection */ public final Flux<T> refCount(int minSubscribers, Duration gracePeriod, Scheduler scheduler) { return onAssembly(new FluxRefCountGrace<>(this, minSubscribers, gracePeriod, scheduler)); }
/** * Connects this {@link ConnectableFlux} to the upstream source when the specified amount of * {@link org.reactivestreams.Subscriber} subscribes and calls the supplied consumer with a runnable that allows disconnecting. * <p> * <img class="marble" src="doc-files/marbles/autoConnectWithMinSubscribers.svg" alt=""> * * @param minSubscribers the minimum number of subscribers * @param cancelSupport the consumer that will receive the {@link Disposable} that allows disconnecting * @return a {@link Flux} that connects to the upstream source when the given amount of subscribers subscribed */ public final Flux<T> autoConnect(int minSubscribers, Consumer<? super Disposable> cancelSupport) { if (minSubscribers == 0) { connect(cancelSupport); return this; } if(this instanceof Fuseable){ return onAssembly(new FluxAutoConnectFuseable<>(this, minSubscribers, cancelSupport)); } return onAssembly(new FluxAutoConnect<>(this, minSubscribers, cancelSupport)); }
/** * Connects to the upstream source when the given number of {@link org.reactivestreams.Subscriber} subscribes and disconnects * when all Subscribers cancelled or the upstream source completed. * * <p> * <img class="marble" src="doc-files/marbles/refCountWithMinSubscribers.svg" alt=""> * * @param minSubscribers the number of subscribers expected to subscribe before connection * * @return a reference counting {@link Flux} */ public final Flux<T> refCount(int minSubscribers) { return onAssembly(new FluxRefCount<>(this, minSubscribers)); }
/** * Connects to the upstream source when the given number of {@link org.reactivestreams.Subscriber} subscribes. * Disconnection can happen in two scenarios: when the upstream source completes (or errors) then * there is an immediate disconnection. However, when all subscribers have cancelled, * a <strong>deferred</strong> disconnection is scheduled. If any new subscriber comes * in during the {@code gracePeriod} that follows, the disconnection is cancelled. * * <p> * <img class="marble" src="doc-files/marbles/refCountWithMinSubscribersAndGracePeriod.svg" alt=""> * * @param minSubscribers the number of subscribers expected to subscribe before connection * @param gracePeriod the {@link Duration} for which to wait for new subscribers before actually * disconnecting when all subscribers have cancelled. * @param scheduler the {@link Scheduler} on which to run timeouts * * @return a reference counting {@link Flux} with a grace period for disconnection */ public final Flux<T> refCount(int minSubscribers, Duration gracePeriod, Scheduler scheduler) { return onAssembly(new FluxRefCountGrace<>(this, minSubscribers, gracePeriod, scheduler)); }
/** * Connects this {@link ConnectableFlux} to the upstream source when the specified amount of * {@link org.reactivestreams.Subscriber} subscribes and calls the supplied consumer with a runnable that allows disconnecting. * <p> * <img class="marble" src="doc-files/marbles/autoConnectWithMinSubscribers.svg" alt=""> * * @param minSubscribers the minimum number of subscribers * @param cancelSupport the consumer that will receive the {@link Disposable} that allows disconnecting * @return a {@link Flux} that connects to the upstream source when the given amount of subscribers subscribed */ public final Flux<T> autoConnect(int minSubscribers, Consumer<? super Disposable> cancelSupport) { if (minSubscribers == 0) { connect(cancelSupport); return this; } if(this instanceof Fuseable){ return onAssembly(new FluxAutoConnectFuseable<>(this, minSubscribers, cancelSupport)); } return onAssembly(new FluxAutoConnect<>(this, minSubscribers, cancelSupport)); }