JavaScript is disabled on your browser.
Skip navigation links
io.reactivex.rxjava3.flowables

Class ConnectableFlowable<T>

  • Type Parameters:
    T - the type of items emitted by the ConnectableFlowable
    All Implemented Interfaces:
    Publisher<T>


    public abstract class ConnectableFlowable<T>
    extends Flowable<T>
    A ConnectableFlowable resembles an ordinary Flowable, except that it does not begin emitting items when it is subscribed to, but only when its connect(io.reactivex.rxjava3.functions.Consumer<? super io.reactivex.rxjava3.disposables.Disposable>) method is called. In this way you can wait for all intended Subscribers to Flowable.subscribe() to the Flowable before the Flowable begins emitting items.

    When the upstream terminates, the ConnectableFlowable remains in this terminated state and, depending on the actual underlying implementation, relays cached events to late Subscribers. In order to reuse and restart this ConnectableFlowable, the reset() method has to be called. When called, this ConnectableFlowable will appear as fresh, unconnected source to new Subscribers. Disposing the connection will reset the ConnectableFlowable to its fresh state and there is no need to call reset() in this case.

    Note that although connect() and reset() are safe to call from multiple threads, it is recommended a dedicated thread or business logic manages the connection or resetting of a ConnectableFlowable so that there is no unwanted signal loss due to early connect() or reset() calls while Subscribers are still being subscribed to to this ConnectableFlowable to receive signals from the get go.

    Since:
    2.0.0
    See Also:
    RxJava Wiki: Connectable Observable Operators
    • Constructor Detail

      • ConnectableFlowable

        public ConnectableFlowable()
    • Method Detail

      • connect

        @SchedulerSupport(value="none")
        public abstract void connect(@NonNull Consumer<? super Disposable> connection)
        Instructs the ConnectableFlowable to begin emitting the items from its underlying Flowable to its Subscribers.
        Scheduler:
        The behavior is determined by the implementor of this abstract class.
        Parameters:
        connection - the action that receives the connection subscription before the subscription to source happens allowing the caller to synchronously disconnect a synchronous source
        Throws:
        NullPointerException - if connection is null
        See Also:
        ReactiveX documentation: Connect
      • reset

        @SchedulerSupport(value="none")
        public abstract void reset()
        Resets this ConnectableFlowable into its fresh state if it has terminated.

        Calling this method on a fresh or active ConnectableFlowable has no effect.

        Scheduler:
        The behavior is determined by the implementor of this abstract class.
        Since:
        3.0.0
      • refCount

        @CheckReturnValue
         @SchedulerSupport(value="none")
         @BackpressureSupport(value=PASS_THROUGH)
         @NonNull
        public final @NonNull Flowable<T> refCount(int subscriberCount)
        Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect if all subscribers have unsubscribed.
        Backpressure:
        The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
        Scheduler:
        This refCount overload does not operate on any particular Scheduler.

        History: 2.1.14 - experimental

        Parameters:
        subscriberCount - the number of subscribers required to connect to the upstream
        Returns:
        the new Flowable instance
        Throws:
        IllegalArgumentException - if subscriberCount is non-positive
        Since:
        2.2
      • refCount

        @CheckReturnValue
         @SchedulerSupport(value="custom")
         @BackpressureSupport(value=PASS_THROUGH)
         @NonNull
        public final @NonNull Flowable<T> refCount(long timeout,
         @NonNull TimeUnit unit,
         @NonNull Scheduler scheduler)
        Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches 1 and disconnect after the specified timeout if all subscribers have unsubscribed.
        Backpressure:
        The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
        Scheduler:
        This refCount overload operates on the specified Scheduler.

        History: 2.1.14 - experimental

        Parameters:
        timeout - the time to wait before disconnecting after all subscribers unsubscribed
        unit - the time unit of the timeout
        scheduler - the target scheduler to wait on before disconnecting
        Returns:
        the new Flowable instance
        Throws:
        NullPointerException - if unit or scheduler is null
        Since:
        2.2
      • refCount

        @CheckReturnValue
         @SchedulerSupport(value="io.reactivex:computation")
         @BackpressureSupport(value=PASS_THROUGH)
         @NonNull
        public final @NonNull Flowable<T> refCount(int subscriberCount,
         long timeout,
         @NonNull TimeUnit unit)
        Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect after the specified timeout if all subscribers have unsubscribed.
        Backpressure:
        The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
        Scheduler:
        This refCount overload operates on the computation Scheduler.

        History: 2.1.14 - experimental

        Parameters:
        subscriberCount - the number of subscribers required to connect to the upstream
        timeout - the time to wait before disconnecting after all subscribers unsubscribed
        unit - the time unit of the timeout
        Returns:
        the new Flowable instance
        Throws:
        NullPointerException - if unit is null
        IllegalArgumentException - if subscriberCount is non-positive
        Since:
        2.2
        See Also:
        refCount(int, long, TimeUnit, Scheduler)
      • refCount

        @CheckReturnValue
         @SchedulerSupport(value="custom")
         @BackpressureSupport(value=PASS_THROUGH)
         @NonNull
        public final @NonNull Flowable<T> refCount(int subscriberCount,
         long timeout,
         @NonNull TimeUnit unit,
         @NonNull Scheduler scheduler)
        Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect after the specified timeout if all subscribers have unsubscribed.
        Backpressure:
        The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
        Scheduler:
        This refCount overload operates on the specified Scheduler.

        History: 2.1.14 - experimental

        Parameters:
        subscriberCount - the number of subscribers required to connect to the upstream
        timeout - the time to wait before disconnecting after all subscribers unsubscribed
        unit - the time unit of the timeout
        scheduler - the target scheduler to wait on before disconnecting
        Returns:
        the new Flowable instance
        Throws:
        NullPointerException - if unit or scheduler is null
        IllegalArgumentException - if subscriberCount is non-positive
        Since:
        2.2
      • autoConnect

        @NonNull
         @CheckReturnValue
         @BackpressureSupport(value=PASS_THROUGH)
         @SchedulerSupport(value="none")
        public @NonNull Flowable<T> autoConnect()
        Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the first Subscriber subscribes.

        The connection happens after the first subscription and happens at most once during the lifetime of the returned Flowable. If this ConnectableFlowable terminates, the connection is never renewed, no matter how Subscribers come and go. Use refCount() to renew a connection or dispose an active connection when all Subscribers have cancelled their Subscriptions.

        This overload does not allow disconnecting the connection established via connect(Consumer). Use the autoConnect(int, Consumer) overload to gain access to the Disposable representing the only connection.

        Backpressure:
        The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's behavior.
        Scheduler:
        autoConnect does not operate by default on a particular Scheduler.
        Returns:
        a new Flowable instance that automatically connects to this ConnectableFlowable when the first Subscriber subscribes
        See Also:
        refCount(), autoConnect(int, Consumer)
      • autoConnect

        @NonNull
         @CheckReturnValue
         @BackpressureSupport(value=PASS_THROUGH)
         @SchedulerSupport(value="none")
        public @NonNull Flowable<T> autoConnect(int numberOfSubscribers)
        Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the specified number of Subscribers subscribe to it.

        The connection happens after the given number of subscriptions and happens at most once during the lifetime of the returned Flowable. If this ConnectableFlowable terminates, the connection is never renewed, no matter how Subscribers come and go. Use refCount() to renew a connection or dispose an active connection when all Subscribers have cancelled their Subscriptions.

        This overload does not allow disconnecting the connection established via connect(Consumer). Use the autoConnect(int, Consumer) overload to gain access to the Disposable representing the only connection.

        Backpressure:
        The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's behavior.
        Scheduler:
        autoConnect does not operate by default on a particular Scheduler.
        Parameters:
        numberOfSubscribers - the number of subscribers to await before calling connect on the ConnectableFlowable. A non-positive value indicates an immediate connection.
        Returns:
        a new Flowable instance that automatically connects to this ConnectableFlowable when the specified number of Subscribers subscribe to it
      • autoConnect

        @NonNull
         @CheckReturnValue
         @BackpressureSupport(value=PASS_THROUGH)
         @SchedulerSupport(value="none")
        public @NonNull Flowable<T> autoConnect(int numberOfSubscribers,
         @NonNull Consumer<? super Disposable> connection)
        Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the specified number of Subscribers subscribe to it and calls the specified callback with the Disposable associated with the established connection.

        The connection happens after the given number of subscriptions and happens at most once during the lifetime of the returned Flowable. If this ConnectableFlowable terminates, the connection is never renewed, no matter how Subscribers come and go. Use refCount() to renew a connection or dispose an active connection when all Subscribers have cancelled their Subscriptions.

        Backpressure:
        The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's behavior.
        Scheduler:
        autoConnect does not operate by default on a particular Scheduler.
        Parameters:
        numberOfSubscribers - the number of subscribers to await before calling connect on the ConnectableFlowable. A non-positive value indicates an immediate connection.
        connection - the callback Consumer that will receive the Disposable representing the established connection
        Returns:
        a new Flowable instance that automatically connects to this ConnectableFlowable when the specified number of Subscribers subscribe to it and calls the specified callback with the Disposable associated with the established connection
        Throws:
        NullPointerException - if connection is null
Skip navigation links

AltStyle によって変換されたページ (->オリジナル) /