Future

public interface Future
Known Indirect Subclasses

Futures represent the eventual completion of an asynchronous operation. A future has one of three FutureStates, which can be obtained with getState():

  • FutureState.PENDING - The operation is still pending. The result of the operation isn't available yet and any associated callback hasn't yet been invoked.
  • FutureState.DONE - The operation is complete, and a result is available.
  • FutureState.CANCELLED - The operation has been cancelled.

A Future starts in the FutureState.PENDING state and transitions to FutureState.DONE upon completion. If the future is cancelled using cancel(), then its state may become FutureState.CANCELLED (see cancelling a future for caveats).

Obtaining results from a Future

There are two ways of obtaining results from a Future:

Polling a Future

When the Future is created, its FutureState is set to FutureState.PENDING. You may poll the future using getState() to query the state of the asynchronous operation. When its state is FutureState.DONE, you can obtain the operation's result.

Using a callback to obtain Future results

The operation's result can be reported via a callback. When providing a callback, ARCore will invoke the given function when the operation is complete, unless the future has been cancelled using cancel(). This callback will be invoked on the main thread.

Cancelling a Future

You can try to cancel a Future by calling cancel(). Due to multi-threading, it is possible that the cancel operation is not successful. The return value indicates if the cancellation was successful.

If the cancellation is successful, then any associated callback will never be called.

Public Methods

abstract boolean
cancel()
Tries to cancel the execution of this operation.
abstract FutureState
getState()
Get the current state of the future.

Public Methods

cancel

public abstract boolean cancel()

Tries to cancel the execution of this operation. If the operation was cancelled by this invocation, this method returns true and the associated callback (if any) will never be invoked.

getState

public abstract FutureState getState()

Get the current state of the future.