Interface IPromise<T>

All Superinterfaces:
Callback<T>, java.io.Serializable
All Known Implementing Classes:
CallbackWrapper, Promise

public interface IPromise<T>
extends Callback<T>
IPromise interface. Promise is another term for Future, to avoid naming clashes with JDK. The only implementation is "Promise" currently. I try to stick to ES6/7 terminology where possible.
  • Field Summary

    Fields inherited from interface org.nustaq.kontraktor.Callback

    CONT
  • Method Summary

    Modifier and Type Method Description
    default T await()
    schedule other events/messages until future is resolved/settled (Nonblocking wait).
    T await​(long timeoutMillis)
    schedule other events/messages until future is resolved/settled (Nonblocking delay).
    default IPromise<T> awaitPromise()
    similar to await but does not unwrap the promise.
    IPromise<T> awaitPromise​(long timeout)
    schedule other events/messages until future is resolved/settled (Nonblocking delay).
    <OUT> IPromise<OUT> catchError​(java.util.function.Consumer<java.lang.Object> function)
    called if an error has been signaled by one of the futures in the previous future chain.
    <OUT> IPromise<OUT> catchError​(java.util.function.Function<java.lang.Object,​IPromise<OUT>> function)
    called if an error has been signaled by one of the futures in the previous future chain.
    T get()
    Warning: this is different to JDK's BLOCKING future
    java.lang.Object getError()  
    boolean isSettled()  
    default IPromise<T> onError​(java.util.function.Consumer<java.lang.Object> errorHandler)
    called when an error is set as the result forwards to (new) "catchError" variant.
    default IPromise<T> onResult​(java.util.function.Consumer<T> resultHandler)
    called when a valid result of a future becomes available.
    default IPromise<T> onTimeout​(java.lang.Runnable timeoutHandler)  
    IPromise<T> onTimeout​(java.util.function.Consumer timeoutHandler)
    called when the async call times out. see 'timeOutIn'
    IPromise<T> then​(java.lang.Runnable result)
    called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.
    <OUT> IPromise<OUT> then​(java.util.function.Consumer<T> function)
    called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.
    IPromise<T> then​(Callback<T> result)
    called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.
    <OUT> IPromise<OUT> thenAnd​(java.util.function.Function<T,​IPromise<OUT>> function)
    called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.
    IPromise<T> thenAnd​(java.util.function.Supplier<IPromise<T>> result)
    called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.
    IPromise<T> timeoutIn​(long millis)
    tellMsg the future to call the onTimeout callback in N milliseconds if future is not settled until then

    Methods inherited from interface org.nustaq.kontraktor.Callback

    complete, complete, finish, isTerminated, pipe, reject, resolve, resolve
  • Method Details

    • then

      IPromise<T> then​(java.lang.Runnable result)
      called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMehod().then( () -> furtherProcessing() );
      Returns:
      a future ressolved after this
    • then

      IPromise<T> then​(Callback<T> result)
      called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMehod().then( () -> furtherProcessing() );
      Returns:
      a future ressolved with the Callable result after this
    • thenAnd

      IPromise<T> thenAnd​(java.util.function.Supplier<IPromise<T>> result)
      called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMehod().then( () -> { furtherProcessing(); return new Promise("result"); } );
      Returns:
      a future ressolved with the Supüplier result after this
    • thenAnd

      <OUT> IPromise<OUT> thenAnd​(java.util.function.Function<T,​IPromise<OUT>> function)
      called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMehod().then( () -> { furtherProcessing(); return new Promise("result"); } );
      Returns:
      a future ressolved with the Function result after this
    • then

      <OUT> IPromise<OUT> then​(java.util.function.Consumer<T> function)
      called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMethod().then( () -> { furtherProcessing(); return new Promise("result"); } );
      Returns:
      a future ressolved empty after this
    • catchError

      <OUT> IPromise<OUT> catchError​(java.util.function.Function<java.lang.Object,​IPromise<OUT>> function)
      called if an error has been signaled by one of the futures in the previous future chain. e.e. actor.async().then( ).then( ).then( ).catchError( error -> .. );
    • catchError

      <OUT> IPromise<OUT> catchError​(java.util.function.Consumer<java.lang.Object> function)
      called if an error has been signaled by one of the futures in the previous future chain. e.e. actor.async().then( ).then( ).then( ).catchError( () -> .. );
    • onResult

      default IPromise<T> onResult​(java.util.function.Consumer<T> resultHandler)
      called when a valid result of a future becomes available. forwards to (new) "then" variant.
      Returns:
    • onError

      default IPromise<T> onError​(java.util.function.Consumer<java.lang.Object> errorHandler)
      called when an error is set as the result forwards to (new) "catchError" variant.
      Returns:
    • onTimeout

      IPromise<T> onTimeout​(java.util.function.Consumer timeoutHandler)
      called when the async call times out. see 'timeOutIn'
      Parameters:
      timeoutHandler -
      Returns:
    • onTimeout

      default IPromise<T> onTimeout​(java.lang.Runnable timeoutHandler)
    • get

      T get()
      Warning: this is different to JDK's BLOCKING future
      Returns:
      result if avaiable (no blocking no awaiting).
    • await

      default T await()
      schedule other events/messages until future is resolved/settled (Nonblocking wait). In case this is called from a non-actor thread, the current thread is blocked until the result is avaiable. If the future is rejected (resolves to an error) an exception is raised. This method is aequivalent to await(15000) = 15 seconds timeout. use await(0) to wait infinetely.
      Returns:
      the futures result or throw exception in case of error
    • await

      T await​(long timeoutMillis)
      schedule other events/messages until future is resolved/settled (Nonblocking delay). In case this is called from a non-actor thread, the current thread is blocked until the result is avaiable. If the future is rejected (resolves to an error) an excpetion is raised. if timeout is 0l - wait forever.
      Returns:
      the futures result or throw exception in case of error
    • awaitPromise

      IPromise<T> awaitPromise​(long timeout)
      schedule other events/messages until future is resolved/settled (Nonblocking delay). In case this is called from a non-actor thread, the current thread is blocked until the result is avaiable.
      Parameters:
      timeout -
      Returns:
      the settled promise. No Exception is thrown, but the exception can be obtained by IPromise.getError()
    • awaitPromise

      default IPromise<T> awaitPromise()
      similar to await but does not unwrap the promise. So a fulfilled promise is returned. In case of errors, no exception is thrown to the caller but the promise error is set.
      Returns:
    • getError

      java.lang.Object getError()
      Returns:
      error if avaiable
    • timeoutIn

      IPromise<T> timeoutIn​(long millis)
      tellMsg the future to call the onTimeout callback in N milliseconds if future is not settled until then
      Parameters:
      millis -
      Returns:
      this for chaining
    • isSettled

      boolean isSettled()
      Returns:
      wether an error or a result has been set to this future