AsyncOperation<T> Class

  • java.lang.Object
    • java.util.concurrent.Future<T>
      • com.microsoft.connecteddevices.AsyncOperation<T>

Type Parameters

T

public class AsyncOperation

An operation that has a future result of type T or a possible exception. This class is a slightly simplified version of the android api level 24 CompletableFuture class

Implements the standard Future interface, and also provides basic continuation functionality. Please see CompletableFuture for detailed information on the how to use this class.

The important differences between CompletableFuture and AsyncOperation are as follows: 1. AsyncOperation's default asynchronous executor is Executors.newCachedThreadPool() whereas CompletableFuture uses ForkJoinPool.commonPool(). 2. AsyncOperation lacks obtrudeException and obtrudeValue methods.

Constructor Summary

Constructor Description
AsyncOperation()

Creates a new AsyncOperation

Method Summary

Modifier and Type Method and Description
<U> AsyncOperation<U> _handleAsyncInternal(AsyncOperation.ResultBiFunction<? super T, ? super Throwable, ? extends U> action, Executor executor)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

AsyncOperation<T> _whenCompleteAsyncInternal(AsyncOperation.ResultBiConsumer<? super T, ? super Throwable> action, Executor executor)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

AsyncOperation<Void> acceptEither( @NonNull AsyncOperation<? extends T> other, @NonNull AsyncOperation.ResultConsumer<? super T> action)

The acceptEither trio of functions run a passed in ResultConsumer when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> acceptEitherAsync( @NonNull AsyncOperation<? extends T> other, @NonNull AsyncOperation.ResultConsumer<? super T> action)

The acceptEither trio of functions run a passed in ResultConsumer when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> acceptEitherAsync( @NonNull AsyncOperation<? extends T> other, AsyncOperation.ResultConsumer<? super T> action, @NonNull Executor executor)

The acceptEither trio of functions run a passed in ResultConsumer when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> allOf(@NonNull AsyncOperation<?>... operations)

Creates an operation that will complete when all of the passed operations complete.

AsyncOperation<Object> anyOf(@NonNull AsyncOperation<?>... operations)

Creates an operation that will complete when any of the passed operations complete.

<U> AsyncOperation<U> applyToEither( @NonNull AsyncOperation<? extends T> other, @NonNull AsyncOperation.ResultFunction<? super T, U> action)

The applyToEither trio of functions run a passed in ResultFunction when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

<U> AsyncOperation<U> applyToEitherAsync( @NonNull AsyncOperation<? extends T> other, @NonNull AsyncOperation.ResultFunction<? super T, U> action)

The applyToEither trio of functions run a passed in ResultFunction when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

<U> AsyncOperation<U> applyToEitherAsync(@NonNull AsyncOperation<? extends T> other, @NonNull AsyncOperation.ResultFunction<? super T, U> action, @NonNull Executor executor)

The applyToEither trio of functions run a passed in ResultFunction when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

boolean cancel(boolean mayInterruptIfRunning)

Attempts to cancel the future and stop waiting for a result.

Cancelling an AsyncOperation causes any threads waiting for the future via get() to immediately receive a CancellationException. The operation execution is not interrupted, but any eventual result from a cancelled call will be ignored.

final void complete(T value)

Completes this operate with a given value.

static<U> AsyncOperation<U> completedFuture(U value)

Creates an operation that is already completed with the given value

final void completeExceptionally(@NonNull Throwable ex)

Sets the exception that will be thrown when the future value is retrieved, and marks the future done.

AsyncOperation<T> exceptionally(@NonNull AsyncOperation.ResultFunction<Throwable, ? extends T> action)

Allows continuations to be attached that only run in the case of an exceptional completion of this operation. Note that there are no *async* variants of exceptionally so the action should not be long running as it may be blocking the thread that completed this operation or the calling thread ( in the case of an already completed operation).

T get()

Gets the future value, waiting if necessary until the future is done.

T get(long timeout, @NonNull TimeUnit unit)

Attempts to get the future value, waiting if necessary until the future is done or until a timeout.

final T getNow(T valueIfAbsent)

Gets the value of the operation immediately returning a passed in value if the operation is not yet complete.

int getNumberOfDependents()

Gets an estimated number of operations that are dependent on this operation. This is not intended to be used for synchronization / scheduling purposes.

<U> AsyncOperation<U> handle(@NonNull AsyncOperation.ResultBiFunction<? super T, ? super Throwable, ? extends U> action)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

<U> AsyncOperation<U> handleAsync(@NonNull AsyncOperation.ResultBiFunction<? super T, ? super Throwable, ? extends U> action)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

<U> AsyncOperation<U> handleAsync( @NonNull AsyncOperation.ResultBiFunction<? super T, ? super Throwable, ? extends U> action, @NonNull Executor executor)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

boolean isCancelled()

Checks if the future has been successfully cancelled.

boolean isCompletedExceptionally()

Checks if the operation completed in any exceptional way (cancellation or completeExceptionally)

boolean isDone()

Checks if the future is done. The future is done when the result is set or an exception is set.

T join()

Gets the future value, waiting if necessary until the future is done. Unlike get() join throws a CompletionException if any exception occured in the process of completing this operation

AsyncOperation<Void> runAfterBoth(@NonNull AsyncOperation<?> other, @NonNull Runnable action)

The runAfterBoth trio of functions run a passed in Runnable when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> runAfterBothAsync(@NonNull AsyncOperation<?> other, @NonNull Runnable action)

The runAfterBoth trio of functions run a passed in Runnable when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> runAfterBothAsync(@NonNull AsyncOperation<?> other, @NonNull Runnable action, @NonNull Executor executor)

The runAfterBoth trio of functions run a passed in Runnable when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> runAfterEither(@NonNull AsyncOperation<?> other, @NonNull Runnable action)

The runAfterEither trio of functions run a passed in Runnable when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> runAfterEitherAsync(@NonNull AsyncOperation<?> other, @NonNull Runnable action)

The runAfterEither trio of functions run a passed in Runnable when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> runAfterEitherAsync( @NonNull AsyncOperation<?> other, @NonNull Runnable action, @NonNull Executor executor)

The runAfterEither trio of functions run a passed in Runnable when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

AsyncOperation<Void> runAsync(@NonNull Runnable runnable)

Creates an operation that will run the passed in Runnable on the default executor

AsyncOperation<Void> runAsync(@NonNull Runnable runnable, @NonNull Executor executor)

Creates an operation that will run the passed in Runnable on the passed in executor

static<U> AsyncOperation<U> supplyAsync(@NonNull AsyncOperation.Supplier<U> supplier)

Creates an operation that will use the default executor to get a value from the supplier

static<U> AsyncOperation<U> supplyAsync(@NonNull AsyncOperation.Supplier<U> supplier, @NonNull Executor executor)

Creates an operation that will use the passed in executor to get a value from the supplier

AsyncOperation<Void> thenAccept(@NonNull ResultConsumer<? super T> action)

The thenAccept trio of functions (thenAccept(action), thenAcceptAsync(action), and thenAcceptAsync(action,Executor)) run a passed in ResultConsumer when this operation completes successfully.

AsyncOperation<Void> thenAcceptAsync(@NonNull ResultConsumer<? super T> action)

The thenAccept trio of functions (thenAccept(action), thenAcceptAsync(action), and thenAcceptAsync(action,Executor)) run a passed in ResultConsumer when this operation completes successfully.

AsyncOperation<Void> thenAcceptAsync(@NonNull ResultConsumer<? super T> action, @NonNull Executor executor)

The thenAccept trio of functions (thenAccept(action), thenAcceptAsync(action), and thenAcceptAsync(action,Executor)) run a passed in ResultConsumer when this operation completes successfully.

<U> AsyncOperation<Void> thenAcceptBoth( @NonNull AsyncOperation<? extends U> other, @NonNull AsyncOperation.ResultBiConsumer<? super T, ? super U> action)

The thenAcceptBoth trio of functions run a passed in ResultConsumer when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

<U> AsyncOperation<Void> thenAcceptBothAsync( @NonNull AsyncOperation<? extends U> other, @NonNull AsyncOperation.ResultBiConsumer<? super T, ? super U> action)

The thenAcceptBoth trio of functions run a passed in ResultConsumer when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

<U> AsyncOperation<Void> thenAcceptBothAsync(@NonNull AsyncOperation<? extends U> other, @NonNull AsyncOperation.ResultBiConsumer<? super T, ? super U> action, @NonNull Executor executor)

The thenAcceptBoth trio of functions run a passed in ResultConsumer when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

<U> AsyncOperation<U> thenApply(@NonNull ResultFunction<? super T, ? extends U> action)

The thenApply trio of functions (thenApplyAsync(action), thenApplyAsync(action), and thenApplyAsync(action,Executor)) run a passed in ResultFunction when this operation completes successfully.

<U> AsyncOperation<U> thenApplyAsync(@NonNull ResultFunction<? super T, ? extends U> action)

The thenApply trio of functions (thenApplyAsync(action), thenApplyAsync(action), and thenApplyAsync(action,Executor)) run a passed in ResultFunction when this operation completes successfully.

<U> AsyncOperation<U> thenApplyAsync(@NonNull ResultFunction<? super T, ? extends U> action, @NonNull Executor executor)

The thenApply trio of functions (thenApplyAsync(action), thenApplyAsync(action), and thenApplyAsync(action,Executor)) run a passed in ResultFunction when this operation completes successfully.

<U, V> AsyncOperation<V> thenCombine( @NonNull AsyncOperation<? extends U> other, @NonNull AsyncOperation.ResultBiFunction<? super T, ? super U, ? extends V> action)

The thenCombine trio of functions run a passed in ResultFunction when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

<U, V> AsyncOperation<V> thenCombineAsync( @NonNull AsyncOperation<? extends U> other, @NonNull AsyncOperation.ResultBiFunction<? super T, ? super U, ? extends V> action)

The thenCombine trio of functions run a passed in ResultFunction when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

<U, V> AsyncOperation<V> thenCombineAsync(@NonNull AsyncOperation<? extends U> other, @NonNull AsyncOperation.ResultBiFunction<? super T, ? super U, ? extends V> action, @NonNull Executor executor)

The thenCombine trio of functions run a passed in ResultFunction when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

<U> AsyncOperation<U> thenCompose(@NonNull AsyncOperation.ResultFunction<? super T, ? extends AsyncOperation<U>> action)

The thenCompose trio of functions run a passed in ResultFunction when this operation completes successfully. The ResultFunction returns an AsyncOperation<T> and the return operation from this call returns a AsyncOperation<T> as opposed to a AsyncOperation<AsyncOperation<T>>

<U> AsyncOperation<U> thenComposeAsync(@NonNull AsyncOperation.ResultFunction<? super T, ? extends AsyncOperation<U>> action)

The thenCompose trio of functions run a passed in ResultFunction when this operation completes successfully. The ResultFunction returns an AsyncOperation<T> and the return operation from this call returns a AsyncOperation<T> as opposed to a AsyncOperation<AsyncOperation<T>>

<U> AsyncOperation<U> thenComposeAsync(AsyncOperation.ResultFunction<? super T, ? extends AsyncOperation<U>> action, Executor executor)

The thenCompose trio of functions run a passed in ResultFunction when this operation completes successfully. The ResultFunction returns an AsyncOperation<T> and the return operation from this call returns a AsyncOperation<T> as opposed to a AsyncOperation<AsyncOperation<T>>

AsyncOperation<Void> thenRun(@NonNull Runnable action)

The thenRun trio of functions (thenRun(action), thenRunAsync(action), and thenRunAsync(action,Executor)) run a passed in Runnable when this operation completes successfully.

AsyncOperation<Void> thenRunAsync(@NonNull Runnable action)

The thenRun trio of functions (thenRun(action), thenRunAsync(action), and thenRunAsync(action,Executor)) run a passed in Runnable when this operation completes successfully.

AsyncOperation<Void> thenRunAsync(@NonNull Runnable action, @NonNull Executor executor)

The thenRun trio of functions (thenRun(action), thenRunAsync(action), and thenRunAsync(action,Executor)) run a passed in Runnable when this operation completes successfully.

AsyncOperation<T> whenComplete(@NonNull AsyncOperation.ResultBiConsumer<? super T, ? super Throwable> action)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

AsyncOperation<T> whenCompleteAsync(@NonNull AsyncOperation.ResultBiConsumer<? super T, ? super Throwable> action)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

AsyncOperation<T> whenCompleteAsync( @NonNull AsyncOperation.ResultBiConsumer<? super T, ? super Throwable> action, @NonNull Executor executor)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

Constructor Details

AsyncOperation

public AsyncOperation()

Creates a new AsyncOperation

Method Details

_handleAsyncInternal

protected AsyncOperation _handleAsyncInternal(AsyncOperation.ResultBiFunction action, Executor executor)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

Parameters:

action - Function that will be executed upon completion of this operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

_whenCompleteAsyncInternal

protected AsyncOperation _whenCompleteAsyncInternal(AsyncOperation.ResultBiConsumer action, Executor executor)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

Parameters:

action - Function that will be executed upon completion of this operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

acceptEither

public AsyncOperation acceptEither( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultConsumer action)

The acceptEither trio of functions run a passed in ResultConsumer when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - ResultConsumer that will be executed upon completion of either operation

Returns:

A new async operation that will complete based on the outcome of passed in action

acceptEitherAsync

public AsyncOperation acceptEitherAsync( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultConsumer action)

The acceptEither trio of functions run a passed in ResultConsumer when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - ResultConsumer that will be executed upon completion of either operation

Returns:

A new async operation that will complete based on the outcome of passed in action

acceptEitherAsync

public AsyncOperation acceptEitherAsync( @NonNull AsyncOperation other, AsyncOperation.ResultConsumer action, @NonNull Executor executor)

The acceptEither trio of functions run a passed in ResultConsumer when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - ResultConsumer that will be executed upon completion of either operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

allOf

public static AsyncOperation allOf(@NonNull AsyncOperation... operations)

Creates an operation that will complete when all of the passed operations complete.

Parameters:

operations - list of operations to "AND" together

Returns:

A new async operation that will complete when all operations complete

anyOf

public static AsyncOperation anyOf(@NonNull AsyncOperation... operations)

Creates an operation that will complete when any of the passed operations complete.

Parameters:

operations - list of operations to "OR" together

Returns:

A new async operation that will complete when any operations complete

applyToEither

public AsyncOperation applyToEither( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultFunction action)

The applyToEither trio of functions run a passed in ResultFunction when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - ResultFunction that will be executed upon completion of either operation

Returns:

A new async operation that will complete based on the outcome of passed in action

applyToEitherAsync

public AsyncOperation applyToEitherAsync( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultFunction action)

The applyToEither trio of functions run a passed in ResultFunction when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - ResultFunction that will be executed upon completion of either operation

Returns:

A new async operation that will complete based on the outcome of passed in action

applyToEitherAsync

public AsyncOperation applyToEitherAsync(@NonNull AsyncOperation other, @NonNull AsyncOperation.ResultFunction action, @NonNull Executor executor)

The applyToEither trio of functions run a passed in ResultFunction when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - ResultFunction that will be executed upon completion of either operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

cancel

public boolean cancel(boolean mayInterruptIfRunning)

Attempts to cancel the future and stop waiting for a result.

Cancelling an AsyncOperation causes any threads waiting for the future via get() to immediately receive a CancellationException. The operation execution is not interrupted, but any eventual result from a cancelled call will be ignored.

Parameters:

mayInterruptIfRunning - ignored because operations cannot be interrupted.

Returns:

true if the future was cancelled before it was completed; false if the future could not be cancelled because it was already completed.

complete

public final void complete(T value)

Completes this operate with a given value.

Parameters:

value - The result of the operation, or null for a successful but empty result.

completedFuture

public static static AsyncOperation completedFuture(U value)

Creates an operation that is already completed with the given value

Parameters:

value - value with which to complete the operation

Returns:

A new async operation that is already completed

completeExceptionally

public final void completeExceptionally(@NonNull Throwable ex)

Sets the exception that will be thrown when the future value is retrieved, and marks the future done.

Parameters:

ex - Throwable with which to complete the operation.

exceptionally

public AsyncOperation exceptionally(@NonNull AsyncOperation.ResultFunction action)

Allows continuations to be attached that only run in the case of an exceptional completion of this operation. Note that there are no *async* variants of exceptionally so the action should not be long running as it may be blocking the thread that completed this operation or the calling thread ( in the case of an already completed operation).

Parameters:

action - the action to perform when the operation completes exceptionally.

get

public T get()

Gets the future value, waiting if necessary until the future is done.

Returns:

The result of the operation, or null for a successful but empty result.

get

public T get(long timeout, @NonNull TimeUnit unit)

Attempts to get the future value, waiting if necessary until the future is done or until a timeout.

Parameters:

timeout
unit

Returns:

The result, or null for a successful but empty result.

getNow

public final T getNow(T valueIfAbsent)

Gets the value of the operation immediately returning a passed in value if the operation is not yet complete.

Parameters:

valueIfAbsent - default value to return if operation isn't complete

Returns:

The operation result, null for a successful but empty result, or the passed in value if the operation is not yet complete.

getNumberOfDependents

public int getNumberOfDependents()

Gets an estimated number of operations that are dependent on this operation. This is not intended to be used for synchronization / scheduling purposes.

Returns:

number of operations currently awaiting this operation to complete.

handle

public AsyncOperation handle(@NonNull AsyncOperation.ResultBiFunction action)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

Parameters:

action - Function that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

handleAsync

public AsyncOperation handleAsync(@NonNull AsyncOperation.ResultBiFunction action)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

Parameters:

action - Function that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

handleAsync

public AsyncOperation handleAsync( @NonNull AsyncOperation.ResultBiFunction action, @NonNull Executor executor)

The handle trio of functions (handle(action), handleAsync(action), and handleAsync(action,Executor)) are the most basic continuation functions upon which the others are built. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed.

Parameters:

action - Function that will be executed upon completion of this operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

isCancelled

public boolean isCancelled()

Checks if the future has been successfully cancelled.

Returns:

if the operation is cancelled

isCompletedExceptionally

public boolean isCompletedExceptionally()

Checks if the operation completed in any exceptional way (cancellation or completeExceptionally)

Returns:

if the operation is completed in an exceptional way (cancellation or explicitly)

isDone

public boolean isDone()

Checks if the future is done. The future is done when the result is set or an exception is set.

Returns:

if the operation is done

join

public T join()

Gets the future value, waiting if necessary until the future is done. Unlike get() join throws a CompletionException if any exception occured in the process of completing this operation

Returns:

The operation result, or null for a successful but empty result.

runAfterBoth

public AsyncOperation runAfterBoth(@NonNull AsyncOperation other, @NonNull Runnable action)

The runAfterBoth trio of functions run a passed in Runnable when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - Runnable that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

runAfterBothAsync

public AsyncOperation runAfterBothAsync(@NonNull AsyncOperation other, @NonNull Runnable action)

The runAfterBoth trio of functions run a passed in Runnable when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - Runnable that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

runAfterBothAsync

public AsyncOperation runAfterBothAsync(@NonNull AsyncOperation other, @NonNull Runnable action, @NonNull Executor executor)

The runAfterBoth trio of functions run a passed in Runnable when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - Runnable that will be executed upon completion of both operations
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

runAfterEither

public AsyncOperation runAfterEither(@NonNull AsyncOperation other, @NonNull Runnable action)

The runAfterEither trio of functions run a passed in Runnable when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - Runnable that will be executed upon completion of either operation

Returns:

A new async operation that will complete based on the outcome of passed in action

runAfterEitherAsync

public AsyncOperation runAfterEitherAsync(@NonNull AsyncOperation other, @NonNull Runnable action)

The runAfterEither trio of functions run a passed in Runnable when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - Runnable that will be executed upon completion of either operation

Returns:

A new async operation that will complete based on the outcome of passed in action

runAfterEitherAsync

public AsyncOperation runAfterEitherAsync( @NonNull AsyncOperation other, @NonNull Runnable action, @NonNull Executor executor)

The runAfterEither trio of functions run a passed in Runnable when either this operation or the passed in operation completes successfully. If the operation that completes does so exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "OR" together
action - Runnable that will be executed upon completion of either operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

runAsync

public static AsyncOperation runAsync(@NonNull Runnable runnable)

Creates an operation that will run the passed in Runnable on the default executor

Parameters:

runnable - action to run

Returns:

A new async operation that will complete when the runnable completes

runAsync

public static AsyncOperation runAsync(@NonNull Runnable runnable, @NonNull Executor executor)

Creates an operation that will run the passed in Runnable on the passed in executor

Parameters:

runnable - action to run
executor - executor on which to run the action

Returns:

A new async operation that will complete when the runnable completes

supplyAsync

public static static AsyncOperation supplyAsync(@NonNull AsyncOperation.Supplier supplier)

Creates an operation that will use the default executor to get a value from the supplier

Parameters:

supplier - supplier from which to get a value to complete this operation

Returns:

A new async operation that will complete with a value from the supplier

supplyAsync

public static static AsyncOperation supplyAsync(@NonNull AsyncOperation.Supplier supplier, @NonNull Executor executor)

Creates an operation that will use the passed in executor to get a value from the supplier

Parameters:

supplier - supplier from which to get a value to complete this operation
executor - executor on which to run the action

Returns:

A new async operation that will complete with a value from the supplier

thenAccept

public AsyncOperation thenAccept(@NonNull ResultConsumer action)

The thenAccept trio of functions (thenAccept(action), thenAcceptAsync(action), and thenAcceptAsync(action,Executor)) run a passed in ResultConsumer when this operation completes successfully.

Parameters:

action - ResultConsumer that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

thenAcceptAsync

public AsyncOperation thenAcceptAsync(@NonNull ResultConsumer action)

The thenAccept trio of functions (thenAccept(action), thenAcceptAsync(action), and thenAcceptAsync(action,Executor)) run a passed in ResultConsumer when this operation completes successfully.

Parameters:

action - ResultConsumer that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

thenAcceptAsync

public AsyncOperation thenAcceptAsync(@NonNull ResultConsumer action, @NonNull Executor executor)

The thenAccept trio of functions (thenAccept(action), thenAcceptAsync(action), and thenAcceptAsync(action,Executor)) run a passed in ResultConsumer when this operation completes successfully.

Parameters:

action - ResultConsumer that will be executed upon completion of this operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

thenAcceptBoth

public AsyncOperation thenAcceptBoth( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultBiConsumer action)

The thenAcceptBoth trio of functions run a passed in ResultConsumer when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - ResultConsumer that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

thenAcceptBothAsync

public AsyncOperation thenAcceptBothAsync( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultBiConsumer action)

The thenAcceptBoth trio of functions run a passed in ResultConsumer when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - ResultConsumer that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

thenAcceptBothAsync

public AsyncOperation thenAcceptBothAsync(@NonNull AsyncOperation other, @NonNull AsyncOperation.ResultBiConsumer action, @NonNull Executor executor)

The thenAcceptBoth trio of functions run a passed in ResultConsumer when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - ResultConsumer that will be executed upon completion of both operations
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

thenApply

public AsyncOperation thenApply(@NonNull ResultFunction action)

The thenApply trio of functions (thenApplyAsync(action), thenApplyAsync(action), and thenApplyAsync(action,Executor)) run a passed in ResultFunction when this operation completes successfully.

Parameters:

action - ResultFunction that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

thenApplyAsync

public AsyncOperation thenApplyAsync(@NonNull ResultFunction action)

The thenApply trio of functions (thenApplyAsync(action), thenApplyAsync(action), and thenApplyAsync(action,Executor)) run a passed in ResultFunction when this operation completes successfully.

Parameters:

action - ResultFunction that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

thenApplyAsync

public AsyncOperation thenApplyAsync(@NonNull ResultFunction action, @NonNull Executor executor)

The thenApply trio of functions (thenApplyAsync(action), thenApplyAsync(action), and thenApplyAsync(action,Executor)) run a passed in ResultFunction when this operation completes successfully.

Parameters:

action - ResultFunction that will be executed upon completion of this operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

thenCombine

public AsyncOperation thenCombine( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultBiFunction action)

The thenCombine trio of functions run a passed in ResultFunction when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - ResultFunction that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

thenCombineAsync

public AsyncOperation thenCombineAsync( @NonNull AsyncOperation other, @NonNull AsyncOperation.ResultBiFunction action)

The thenCombine trio of functions run a passed in ResultFunction when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - ResultFunction that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

thenCombineAsync

public AsyncOperation thenCombineAsync(@NonNull AsyncOperation other, @NonNull AsyncOperation.ResultBiFunction action, @NonNull Executor executor)

The thenCombine trio of functions run a passed in ResultFunction when this operation and the passed in operation completes successfully. If either operation completes exceptionally, the returned operation also completes exceptionally.

Parameters:

other - the other operation to "AND" together
action - ResultFunction that will be executed upon completion of both operations
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

thenCompose

public AsyncOperation thenCompose(@NonNull AsyncOperation.ResultFunction> action)

The thenCompose trio of functions run a passed in ResultFunction when this operation completes successfully. The ResultFunction returns an AsyncOperation<T> and the return operation from this call returns a AsyncOperation<T> as opposed to a AsyncOperation<AsyncOperation<T>>

Parameters:

action - Function that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

thenComposeAsync

public AsyncOperation thenComposeAsync(@NonNull AsyncOperation.ResultFunction> action)

The thenCompose trio of functions run a passed in ResultFunction when this operation completes successfully. The ResultFunction returns an AsyncOperation<T> and the return operation from this call returns a AsyncOperation<T> as opposed to a AsyncOperation<AsyncOperation<T>>

Parameters:

action - Function that will be executed upon completion of both operations

Returns:

A new async operation that will complete based on the outcome of passed in action

thenComposeAsync

public AsyncOperation thenComposeAsync(AsyncOperation.ResultFunction> action, Executor executor)

The thenCompose trio of functions run a passed in ResultFunction when this operation completes successfully. The ResultFunction returns an AsyncOperation<T> and the return operation from this call returns a AsyncOperation<T> as opposed to a AsyncOperation<AsyncOperation<T>>

Parameters:

action - Function that will be executed upon completion of both operations
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

thenRun

public AsyncOperation thenRun(@NonNull Runnable action)

The thenRun trio of functions (thenRun(action), thenRunAsync(action), and thenRunAsync(action,Executor)) run a passed in Runnable when this operation completes successfully.

Parameters:

action - Runnable that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

thenRunAsync

public AsyncOperation thenRunAsync(@NonNull Runnable action)

The thenRun trio of functions (thenRun(action), thenRunAsync(action), and thenRunAsync(action,Executor)) run a passed in Runnable when this operation completes successfully.

Parameters:

action - Runnable that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

thenRunAsync

public AsyncOperation thenRunAsync(@NonNull Runnable action, @NonNull Executor executor)

The thenRun trio of functions (thenRun(action), thenRunAsync(action), and thenRunAsync(action,Executor)) run a passed in Runnable when this operation completes successfully.

Parameters:

action - Runnable that will be executed upon completion of this operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

whenComplete

public AsyncOperation whenComplete(@NonNull AsyncOperation.ResultBiConsumer action)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

Parameters:

action - Function that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

whenCompleteAsync

public AsyncOperation whenCompleteAsync(@NonNull AsyncOperation.ResultBiConsumer action)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

Parameters:

action - Function that will be executed upon completion of this operation

Returns:

A new async operation that will complete based on the outcome of passed in action

whenCompleteAsync

public AsyncOperation whenCompleteAsync( @NonNull AsyncOperation.ResultBiConsumer action, @NonNull Executor executor)

The whenComplete trio of functions (whenComplete(action), whenCompleteAsync(action), and whenCompleteAsync(action,Executor)) are similar to the handle functions. Upon successful or exceptional completion of this operation, the passed in action will be executed allowing both antecedent results and antecedent exceptions to be observed. Unlike handle, the results of the action do not propagate to dependent operations; they observe this stage's exception / result instead of the passed in action's

Parameters:

action - Function that will be executed upon completion of this operation
executor - Executor with which to execute the function

Returns:

A new async operation that will complete based on the outcome of passed in action

Applies to