VIN - The type of the function parameter, or Void if the
function does not expect a parameter.VOUT - The type of the function result, or Void if the function
does not return anything (i.e. it only has side-effects).E - The type of the exception thrown by the function, or
NeverThrowsException if no exception is thrown by the
function.public interface AsyncFunction<VIN,VOUT,E extends Exception> extends Function<VIN,Promise<? extends VOUT,? extends E>,E>
Function which returns a result at some point in the
future.
Exception handling: implementations may fail immediately if an error
is encountered before asynchronous processing begins (e.g. if the function
parameter is invalid). Implementations which do not throw any exceptions
should declare that they throw an exception of type
NeverThrowsException.
Example usage:
public class IsPossiblePrime implements AsyncFunction<String, Boolean, IllegalArgumentException> {
// Executor for asynchronously computing primeness.
private ExecutorService executor = Executors.newCachedThreadPool();
public Promise<Boolean, IllegalArgumentException> apply(String value)
throws IllegalArgumentException {
// Create a promise which will hold the asynchronous result.
final PromiseImpl<Boolean, IllegalArgumentException> promise = PromiseImpl.create();
// Parse the parameter now and potentially immediately throw an
// exception. Parsing could be deferred to the executor in which
// case the exception should be trapped and promise.handleException()
// invoked.
final BigInteger possiblePrime = new BigInteger(value);
// Use an executor to asynchronously determine if the parameter is a
// prime number.
executor.execute(new Runnable() {
@Override
public void run() {
// Set the promised result.
promise.handleResult(possiblePrime.isProbablePrime(1000));
}
});
return promise;
}
}
Function,
NeverThrowsException| Modifier and Type | Method and Description |
|---|---|
Promise<? extends VOUT,? extends E> |
apply(VIN value)
Asynchronously applies this function to the input parameter
value
and returns a Promise for the result. |
Promise<? extends VOUT,? extends E> apply(VIN value) throws E extends Exception
value
and returns a Promise for the result.apply in interface Function<VIN,Promise<? extends VOUT,? extends E extends Exception>,E extends Exception>value - The input parameter.Promise representing the result of applying this
function to value.E - If this function cannot be applied to value.E extends ExceptionCopyright © 2025 Open Identity Platform Community. All rights reserved.