Package io.smallrye.faulttolerance.core
Interface Completer<T>
- Type Parameters:
T- type of the result of the computation
public interface Completer<T>
Creator and controller of a
Future. An asynchronous computation that
produces a future has to create a completer and return its future object.
Afterwards, the completer is used to complete the future either with a value,
using Completer.complete(), or with an error, using
Completer.completeWithError().
If the completer is supplied a cancellation callback using onCancel(Runnable),
a successful cancellation request on the future calls the cancellation callback.
-
Method Summary
Modifier and TypeMethodDescriptionvoidCompletes the future with a value, if pending.voidcompleteWithError(Throwable error) Completes the future with an error, if pending.static <T> Completer<T> create()Creates a new completer.future()Returns the future created and controlled by this completer.voidSets the cancellation callback.
-
Method Details
-
create
Creates a new completer.- Type Parameters:
T- type of the result of the computation- Returns:
- a new completer; never
null
-
complete
Completes the future with a value, if pending. If the future is already complete, does nothing.- Parameters:
value- the value with which the future is completed; may benull
-
completeWithError
Completes the future with an error, if pending. If the future is already complete, does nothing.- Parameters:
error- the error with which the future is completed; must not benull
-
onCancel
Sets the cancellation callback. Note that this method may be called at most once; subsequent calls will result in an exception.- Parameters:
cancellationCallback- the cancellation callback; may not benull
-
future
Returns the future created and controlled by this completer.- Returns:
- the future; never
null
-