Interface IFuture<E>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static IFuture<java.lang.Void> DONE
      A future representing a completed action.
      static IFuture<java.lang.Boolean> FALSE
      A future representing a false result.
      static IFuture<java.lang.Boolean> TRUE
      A future representing a true result.
    • Method Summary

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      void addResultListener​(IResultListener<E> listener)
      Add a result listener.
      <T> IFuture<E> catchEx​(Future<T> delegate)
      Called on exception.
      IFuture<E> catchEx​(java.util.function.Consumer<? super java.lang.Exception> consumer)
      Called on exception.
      IFuture<E> catchEx​(java.util.function.Consumer<? super java.lang.Exception> function, java.lang.Class<?> consumer)
      Called on exception.
      void delegate​(Future<E> delegate)
      Deprecated.
      Use delegateTo.
      void delegateTo​(Future<E> target)
      Forward the result and exception to another future.
      E get()
      Get the result - blocking call.
      E get​(boolean realtime)
      Get the result - blocking call.
      E get​(long timeout)
      Get the result - blocking call.
      E get​(long timeout, boolean realtime)
      Get the result - blocking call.
      E get​(ThreadSuspendable sus)
      Deprecated.
      - From 3.0.
      java.lang.Exception getException()
      Get the exception, if any.
      boolean isDone()
      Test if done, i.e.
      IFuture<? extends E> then​(java.util.function.Consumer<? super E> function)
      Applies a function after the result is available, using the result of this Future as input.
      <T> IFuture<T> thenApply​(java.util.function.Function<? super E,​? extends T> function)
      Applies a function after the result is available, using the result of this Future as input.
      <T> IFuture<T> thenApply​(java.util.function.Function<? super E,​? extends T> function, java.lang.Class<?> futuretype)
      Applies a function after the result is available, using the result of this Future as input.
      <T> IFuture<T> thenCompose​(java.util.function.Function<? super E,​IFuture<T>> function)
      The result of this future is delegated to the given (future-returning) function.
      <T> IFuture<T> thenCompose​(java.util.function.Function<? super E,​IFuture<T>> function, java.lang.Class<?> futuretype)
      The result of this future is delegated to the given (future-returning) function.
    • Field Detail

      • DONE

        static final IFuture<java.lang.Void> DONE
        A future representing a completed action. Can be used as direct return value of methods that do not perform asynchronous operations and do not return a result value.
      • TRUE

        static final IFuture<java.lang.Boolean> TRUE
        A future representing a true result.
      • FALSE

        static final IFuture<java.lang.Boolean> FALSE
        A future representing a false result.
    • Method Detail

      • isDone

        boolean isDone()
        Test if done, i.e. result is available.
        Returns:
        True, if done.
      • getException

        java.lang.Exception getException()
        Get the exception, if any.
        Returns:
        The exception, if any, or null if the future is not yet done or succeeded without exception.
      • get

        E get()
        Get the result - blocking call.
        Returns:
        The future result.
      • get

        E get​(boolean realtime)
        Get the result - blocking call.
        Parameters:
        realtime - Flag, if wait should be realtime (in constrast to simulation time).
        Returns:
        The future result.
      • get

        E get​(long timeout)
        Get the result - blocking call.
        Parameters:
        timeout - The timeout in millis.
        Returns:
        The future result.
      • get

        E get​(long timeout,
              boolean realtime)
        Get the result - blocking call.
        Parameters:
        timeout - The timeout in millis.
        realtime - Flag, if wait should be realtime (in constrast to simulation time).
        Returns:
        The future result.
      • get

        E get​(ThreadSuspendable sus)
        Deprecated.
        - From 3.0. Use the version without suspendable. Will NOT use the suspendable given as parameter. Get the result - blocking call.
        Returns:
        The future result.
      • addResultListener

        void addResultListener​(IResultListener<E> listener)
        Add a result listener.
        Parameters:
        listener - The listener.
      • then

        IFuture<? extends E> then​(java.util.function.Consumer<? super E> function)
        Applies a function after the result is available, using the result of this Future as input.
        Parameters:
        function - Function that takes the result of this future as input and delivers t.
        Returns:
        Future of the result after the function has been applied.
      • thenApply

        <T> IFuture<T> thenApply​(java.util.function.Function<? super E,​? extends T> function)
        Applies a function after the result is available, using the result of this Future as input.
        Parameters:
        function - Function that takes the result of this future as input and delivers t.
        Returns:
        Future of the result after the function has been applied.
      • thenApply

        <T> IFuture<T> thenApply​(java.util.function.Function<? super E,​? extends T> function,
                                 java.lang.Class<?> futuretype)
        Applies a function after the result is available, using the result of this Future as input.
        Parameters:
        function - Function that takes the result of this future as input and delivers t.
        futuretype - The type of the return future.
        Returns:
        Future of the result after the function has been applied.
      • thenCompose

        <T> IFuture<T> thenCompose​(java.util.function.Function<? super E,​IFuture<T>> function)
        The result of this future is delegated to the given (future-returning) function. The result of the function will be available in the returned future.
        Parameters:
        function - Function that takes the result of this future as input and delivers future(t).
        Returns:
        Future of the result of the second async call.
      • thenCompose

        <T> IFuture<T> thenCompose​(java.util.function.Function<? super E,​IFuture<T>> function,
                                   java.lang.Class<?> futuretype)
        The result of this future is delegated to the given (future-returning) function. The result of the function will be available in the returned future.
        Parameters:
        function - Function that takes the result of this future as input and delivers future(t).
        futuretype - The type of the return future. If null, a default future is created.
        Returns:
        Future of the result of the second async call.
      • catchEx

        <T> IFuture<E> catchEx​(Future<T> delegate)
        Called on exception.
        Parameters:
        delegate - The future the exception will be delegated to.
      • catchEx

        IFuture<E> catchEx​(java.util.function.Consumer<? super java.lang.Exception> consumer)
        Called on exception.
        Parameters:
        consumer - The function called with the exception.
      • catchEx

        IFuture<E> catchEx​(java.util.function.Consumer<? super java.lang.Exception> function,
                           java.lang.Class<?> consumer)
        Called on exception.
        Parameters:
        consumer - The function called with the exception.
      • delegate

        void delegate​(Future<E> delegate)
        Deprecated.
        Use delegateTo.
        Delegate the result and exception to another future. Short form for adding a delegation listener.
        Parameters:
        delegate - The other future.
      • delegateTo

        void delegateTo​(Future<E> target)
        Forward the result and exception to another future. Short form for adding a delegation listener.
        Parameters:
        target - The target future.