Package org.nustaq.kontraktor
Interface IPromise<T>
- All Superinterfaces:
Callback<T>,Serializable
- All Known Implementing Classes:
CallbackWrapper,Promise
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
-
Method Summary
Modifier and TypeMethodDescriptiondefault Tawait()schedule other events/messages until future is resolved/settled (Nonblocking wait).await(long timeoutMillis) schedule other events/messages until future is resolved/settled (Nonblocking delay).similar to await but does not unwrap the promise.awaitPromise(long timeout) schedule other events/messages until future is resolved/settled (Nonblocking delay).<OUT> IPromise<OUT>catchError(Consumer<Object> function) called if an error has been signaled by one of the futures in the previous future chain.<OUT> IPromise<OUT>catchError(Function<Object, IPromise<OUT>> function) called if an error has been signaled by one of the futures in the previous future chain.get()Warning: this is different to JDK's BLOCKING futuregetError()booleancalled when an error is set as the result forwards to (new) "catchError" variant.called when a valid result of a future becomes available.called when the async call times out. see 'timeOutIn'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>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.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>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.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.timeoutIn(long millis) tellMsg the future to call the onTimeout callback in N milliseconds if future is not settled until then
-
Method Details
-
then
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
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
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
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
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
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
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
called when a valid result of a future becomes available. forwards to (new) "then" variant.- Returns:
-
onError
called when an error is set as the result forwards to (new) "catchError" variant.- Returns:
-
onTimeout
called when the async call times out. see 'timeOutIn'- Parameters:
timeoutHandler-- Returns:
-
onTimeout
-
get
T get()Warning: this is different to JDK's BLOCKING future- Returns:
- result if avaiable (no blocking no awaiting).
-
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
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
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
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
Object getError()- Returns:
- error if avaiable
-
timeoutIn
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
-