Class AsyncOnSubscribe<S,​T>

    • Constructor Detail

      • AsyncOnSubscribe

        public AsyncOnSubscribe()
    • Method Detail

      • generateState

        protected abstract S generateState()
        Executed once when subscribed to by a subscriber (via call(Subscriber)) to produce a state value. This value is passed into next(S state, Observer observer) on the first iteration. Subsequent iterations of next will receive the state returned by the previous invocation of next.
        Returns:
        the initial state value
      • next

        protected abstract S next​(S state,
                                  long requested,
                                  Observer<Observable<? extends T>> observer)
        Called to produce data to the downstream subscribers. To emit data to a downstream subscriber call observer.onNext(t). To signal an error condition call observer.onError(throwable) or throw an Exception. To signal the end of a data stream call observer.onCompleted(). Implementations of this method must follow the following rules.
        • Must not call observer.onNext(t) more than 1 time per invocation.
        • Must not call observer.onNext(t) concurrently.
        The value returned from an invocation of this method will be passed in as the state argument of the next invocation of this method.
        Parameters:
        state - the state value (from generateState() on the first invocation or the previous invocation of this method.
        requested - the amount of data requested. An observable emitted to the observer should not exceed this amount.
        observer - the observer of data emitted by
        Returns:
        the next iteration's state value
      • onUnsubscribe

        protected void onUnsubscribe​(S state)
        Clean up behavior that is executed after the downstream subscriber's subscription is unsubscribed. This method will be invoked exactly once.
        Parameters:
        state - the last state value returned from next(S, Long, Observer) or generateState() at the time when a terminal event is emitted from next(Object, long, Observer) or unsubscribing.
      • createSingleState

        @Experimental
        public static <S,​T> AsyncOnSubscribe<S,​T> createSingleState​(Func0<? extends S> generator,
                                                                                Action3<? super S,​java.lang.Long,​? super Observer<Observable<? extends T>>> next)
        Generates a synchronous AsyncOnSubscribe that calls the provided next function to generate data to downstream subscribers.
        Type Parameters:
        T - the type of the generated values
        S - the type of the associated state with each Subscriber
        Parameters:
        generator - generates the initial state value (see generateState())
        next - produces data to the downstream subscriber (see next(S, long, Observer))
        Returns:
        an AsyncOnSubscribe that emits data in a protocol compatible with back-pressure.
      • createSingleState

        @Experimental
        public static <S,​T> AsyncOnSubscribe<S,​T> createSingleState​(Func0<? extends S> generator,
                                                                                Action3<? super S,​java.lang.Long,​? super Observer<Observable<? extends T>>> next,
                                                                                Action1<? super S> onUnsubscribe)
        Generates a synchronous AsyncOnSubscribe that calls the provided next function to generate data to downstream subscribers. This overload creates a AsyncOnSubscribe without an explicit clean up step.
        Type Parameters:
        T - the type of the generated values
        S - the type of the associated state with each Subscriber
        Parameters:
        generator - generates the initial state value (see generateState())
        next - produces data to the downstream subscriber (see next(S, long, Observer))
        onUnsubscribe - clean up behavior (see onUnsubscribe(S))
        Returns:
        an AsyncOnSubscribe that emits data downstream in a protocol compatible with back-pressure.
      • createStateful

        @Experimental
        public static <S,​T> AsyncOnSubscribe<S,​T> createStateful​(Func0<? extends S> generator,
                                                                             Func3<? super S,​java.lang.Long,​? super Observer<Observable<? extends T>>,​? extends S> next,
                                                                             Action1<? super S> onUnsubscribe)
        Generates a synchronous AsyncOnSubscribe that calls the provided next function to generate data to downstream subscribers.
        Type Parameters:
        T - the type of the generated values
        S - the type of the associated state with each Subscriber
        Parameters:
        generator - generates the initial state value (see generateState())
        next - produces data to the downstream subscriber (see next(S, long, Observer))
        onUnsubscribe - clean up behavior (see onUnsubscribe(S))
        Returns:
        an AsyncOnSubscribe that emits data downstream in a protocol compatible with back-pressure.
      • createStateful

        @Experimental
        public static <S,​T> AsyncOnSubscribe<S,​T> createStateful​(Func0<? extends S> generator,
                                                                             Func3<? super S,​java.lang.Long,​? super Observer<Observable<? extends T>>,​? extends S> next)
        Generates a synchronous AsyncOnSubscribe that calls the provided next function to generate data to downstream subscribers.
        Type Parameters:
        T - the type of the generated values
        S - the type of the associated state with each Subscriber
        Parameters:
        generator - generates the initial state value (see generateState())
        next - produces data to the downstream subscriber (see next(S, long, Observer))
        Returns:
        an AsyncOnSubscribe that emits data downstream in a protocol compatible with back-pressure.
      • createStateless

        @Experimental
        public static <T> AsyncOnSubscribe<java.lang.Void,​T> createStateless​(Action2<java.lang.Long,​? super Observer<Observable<? extends T>>> next)
        Generates a synchronous AsyncOnSubscribe that calls the provided next function to generate data to downstream subscribers. This overload creates a "state-less" AsyncOnSubscribe which does not have an explicit state value. This should be used when the next function closes over it's state.
        Type Parameters:
        T - the type of the generated values
        Parameters:
        next - produces data to the downstream subscriber (see next(S, long, Observer))
        Returns:
        an AsyncOnSubscribe that emits data downstream in a protocol compatible with back-pressure.
      • createStateless

        @Experimental
        public static <T> AsyncOnSubscribe<java.lang.Void,​T> createStateless​(Action2<java.lang.Long,​? super Observer<Observable<? extends T>>> next,
                                                                                   Action0 onUnsubscribe)
        Generates a synchronous AsyncOnSubscribe that calls the provided next function to generate data to downstream subscribers. This overload creates a "state-less" AsyncOnSubscribe which does not have an explicit state value. This should be used when the next function closes over it's state.
        Type Parameters:
        T - the type of the generated values
        Parameters:
        next - produces data to the downstream subscriber (see next(S, long, Observer))
        onUnsubscribe - clean up behavior (see onUnsubscribe(S))
        Returns:
        an AsyncOnSubscribe that emits data downstream in a protocol compatible with back-pressure.
      • call

        public final void call​(Subscriber<? super T> actualSubscriber)
        Specified by:
        call in interface Action1<S>