Class FutureSubscriber<T>

  • Type Parameters:
    T - the value type
    All Implemented Interfaces:
    FlowableSubscriber<T>, java.util.concurrent.Future<T>, org.reactivestreams.Subscriber<T>, org.reactivestreams.Subscription

    public final class FutureSubscriber<T>
    extends java.util.concurrent.CountDownLatch
    implements FlowableSubscriber<T>, java.util.concurrent.Future<T>, org.reactivestreams.Subscription
    A Subscriber + Future that expects exactly one upstream value and provides it via the (blocking) Future API.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.lang.Throwable error  
      (package private) java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> upstream  
      (package private) T value  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()  
      boolean cancel​(boolean mayInterruptIfRunning)  
      T get()  
      T get​(long timeout, @NonNull java.util.concurrent.TimeUnit unit)  
      boolean isCancelled()  
      boolean isDone()  
      void onComplete()  
      void onError​(java.lang.Throwable t)  
      void onNext​(T t)  
      void onSubscribe​(org.reactivestreams.Subscription s)
      Implementors of this method should make sure everything that needs to be visible in Subscriber.onNext(Object) is established before calling Subscription.request(long).
      void request​(long n)  
      • Methods inherited from class java.util.concurrent.CountDownLatch

        await, await, countDown, getCount, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • value

        T value
      • error

        java.lang.Throwable error
      • upstream

        final java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> upstream
    • Constructor Detail

      • FutureSubscriber

        public FutureSubscriber()
    • Method Detail

      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<T>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<T>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<T>
      • get

        public T get()
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public T get​(long timeout,
                     @NonNull
                     @NonNull java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException,
                     java.util.concurrent.TimeoutException
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • onSubscribe

        public void onSubscribe​(org.reactivestreams.Subscription s)
        Description copied from interface: FlowableSubscriber
        Implementors of this method should make sure everything that needs to be visible in Subscriber.onNext(Object) is established before calling Subscription.request(long). In practice this means no initialization should happen after the request() call and additional behavior is thread safe in respect to onNext.
        Specified by:
        onSubscribe in interface FlowableSubscriber<T>
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<T>
      • onNext

        public void onNext​(T t)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<T>
      • onError

        public void onError​(java.lang.Throwable t)
        Specified by:
        onError in interface org.reactivestreams.Subscriber<T>
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<T>
      • cancel

        public void cancel()
        Specified by:
        cancel in interface org.reactivestreams.Subscription
      • request

        public void request​(long n)
        Specified by:
        request in interface org.reactivestreams.Subscription