GARFuture

Futures in ARCore

Futures represent the eventual completion of an asynchronous operation. A future has one of three states, GARFutureState, which can be obtained with GARFuture.state:

A GARFuture starts in the GARFutureStatePending state and transitions to GARFutureStateDone upon completion. If the future is cancelled using cancel (GARFuture), then its state may become GARFutureStateCancelled (see cancelling a future for caveats).

Obtaining results from a Future

There are two ways of obtaining results from a GARFuture:

Polling a Future

When the GARFuture is created, its GARFutureState is set to GARFutureStatePending. You may poll the future using GARFuture.state to query the state of the asynchronous operation. When its state is GARFutureStateDone, you can obtain the operation's result.

Using a completion handler to obtain Future results

The operation's result can be reported via a completionHandler. When providing a completionHandler, ARCore will invoke the given block when the operation is complete, unless the future has been cancelled using cancel (GARFuture). This completionHandler will be called on the Main thread.

Cancelling a Future

You can try to cancel a GARFuture by calling cancel (GARFuture). 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 completion handler will never be called.

Summary

Inheritance

Inherits from: NSObject
Direct Known Subclasses: GARCreateAnchorOnRooftopFuture , GARCreateAnchorOnTerrainFuture , GARHostCloudAnchorFuture , GARResolveCloudAnchorFuture , GARVPSAvailabilityFuture

Properties

state
The current future state.

Public methods

cancel
BOOL
Cancels the async operation if it's still pending.

Properties

state

@property(nonatomic, readonly) GARFutureState state;

The current future state.

Public methods

cancel

- (BOOL)cancel

Cancels the async operation if it's still pending.

If the operation was cancelled by this invocation, this method returns true and the callback (if any) will never be invoked.