Class ScalarSynchronousObservable<T>

  • Type Parameters:
    T - the value type

    public final class ScalarSynchronousObservable<T>
    extends Observable<T>
    An Observable that emits a single constant scalar value to Subscribers.

    This is a direct implementation of the Observable class to allow identifying it in flatMap and bypass the subscription to it altogether.

    • Field Detail

      • t

        final T t
        The constant scalar value to emit on request.
      • STRONG_MODE

        static final boolean STRONG_MODE
        Indicates that the Producer used by this Observable should be fully threadsafe. It is possible, but unlikely that multiple concurrent requests will arrive to just().
    • Constructor Detail

      • ScalarSynchronousObservable

        protected ScalarSynchronousObservable​(T t)
    • Method Detail

      • createProducer

        static <T> Producer createProducer​(Subscriber<? super T> s,
                                           T v)
        Creates a scalar producer depending on the state of STRONG_MODE.
        Type Parameters:
        T - the type of the scalar value
        Parameters:
        s - the target subscriber
        v - the value to emit
        Returns:
        the created Producer
      • create

        public static <T> ScalarSynchronousObservable<T> create​(T t)
        Constructs a ScalarSynchronousObservable with the given constant value.
        Type Parameters:
        T - the value type
        Parameters:
        t - the value to emit when requested
        Returns:
        the new Observable
      • get

        public T get()
        Returns the scalar constant value directly.
        Returns:
        the scalar constant value directly
      • scalarScheduleOn

        public Observable<T> scalarScheduleOn​(Scheduler scheduler)
        Customized observeOn/subscribeOn implementation which emits the scalar value directly or with less overhead on the specified scheduler.
        Parameters:
        scheduler - the target scheduler
        Returns:
        the new observable
      • scalarFlatMap

        public <R> Observable<R> scalarFlatMap​(Func1<? super T,​? extends Observable<? extends R>> func)
        Given this scalar source as input to a flatMap, avoid one step of subscription and subscribes to the single Observable returned by the function.

        If the functions returns another scalar, no subscription happens and this inner scalar value will be emitted once requested.

        Type Parameters:
        R - the result type
        Parameters:
        func - the mapper function that returns an Observable for the scalar value of this
        Returns:
        the new observable