Package 

Class SimpleSettableFuture

  • All Implemented Interfaces:
    java.util.concurrent.Future

    
    public class SimpleSettableFuture<T>
     implements Future<T>
                        

    A super simple Future-like class that can safely notify another Thread when a value is ready. Does not support canceling.

    • Method Summary

      Modifier and Type Method Description
      void set(@Nullable() T result) Sets the result.
      void setException(Exception exception) Sets the exception.
      boolean cancel(boolean mayInterruptIfRunning)
      boolean isCancelled()
      boolean isDone()
      T get()
      T get(long timeout, TimeUnit unit) Wait up to the timeout time for another Thread to set a value on this future.
      T getOrThrow() Convenience wrapper for get that re-throws get()'s Exceptions as RuntimeExceptions.
      T getOrThrow(long timeout, TimeUnit unit) Convenience wrapper for get that re-throws get()'s Exceptions asRuntimeExceptions.
      • Methods inherited from class java.util.concurrent.Future

        cancel, get, isCancelled, isDone
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • set

         void set(@Nullable() T result)

        Sets the result. If another thread has called get, they will immediately receive thevalue. set or setException must only be called once.

      • setException

         void setException(Exception exception)

        Sets the exception. If another thread has called get, they will immediately receivethe exception. set or setException must only be called once.

      • cancel

         boolean cancel(boolean mayInterruptIfRunning)
      • get

        @Nullable() T get(long timeout, TimeUnit unit)

        Wait up to the timeout time for another Thread to set a value on this future. If a value hasalready been set, this method will return immediately.

        NB: For simplicity, we catch and wrap InterruptedException. Do NOT use this class if you arein the 1% of cases where you actually want to handle that.

      • getOrThrow

        @Nullable() T getOrThrow()

        Convenience wrapper for get that re-throws get()'s Exceptions as RuntimeExceptions.

      • getOrThrow

        @Nullable() T getOrThrow(long timeout, TimeUnit unit)

        Convenience wrapper for get that re-throws get()'s Exceptions asRuntimeExceptions.