# InterruptiblePromise\< T \>

Promises represent the eventual completion of an asynchronous operation.

A promise has one of three states, `https://developers.google.com/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate`, which can be obtained with `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#state`:


- `PromiseState.Pending` - The operation is still pending. The result of the operation isn't available yet.
- `PromiseState.Done` - The operation is complete, and a result is available.
- `PromiseState.Cancelled` - The operation has been cancelled.

<br />

An `InterruptiblePromise` starts in the `PromiseState.Pending` state and transitions to `PromiseState.Done` upon completion. If the Promise is cancelled using `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#cancel`, then its state may become `PromiseState.Cancelled` (see [cancelling a Promise](https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#cancelling-a-promise) for caveats).


### Obtaining results from a Promise

<br />

There are two ways of obtaining results from an `InterruptiblePromise`:


#### Polling a Promise

<br />

When the `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#classGoogle_1_1XR_1_1ARCoreExtensions_1_1Internal_1_1InterruptiblePromise_3_01T_01_4` is created, its `https://developers.google.com/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate` is set to `PromiseState.Pending`. You may poll the future using `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#state` to query the state of the asynchronous operation. When its state is `PromiseState.Done`, you may obtain the operation's result using `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#result`.


#### Use a Unity Coroutine

<br />

Promises use a [`CustomYieldInstruction`](https://docs.unity3d.com/ScriptReference/CustomYieldInstruction.html) to facilitate [Unity coroutines](https://docs.unity3d.com/Manual/Coroutines.html). Use `yield return promiseInstance` to pause execution of your coroutine. Unity will resume execution of your coroutine when `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#state` is no longer `PromiseState.Pending`.



    public void CreatePromise()
    {
       https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/ResolveAnchorOnRooftopPromise#classGoogle_1_1XR_1_1ARCoreExtensions_1_1ResolveAnchorOnRooftopPromise rooftopPromise =
           AnchorManager.ResolveAnchorOnRooftopAsync(...);
       StartCoroutine(CheckRooftopPromise(rooftopPromise));
    }
    private IEnumerator CheckRooftopPromise(ResolveAnchorOnTerrainPromise promise)
    {
       yield return promise;
       if (promise.State == PromiseState.Cancelled) yield break;
       var result = promise.Result;
       /// Use the result of your promise here.
    }

<br />


### Cancelling a Promise

<br />

You can try to cancel an `InterruptiblePromise` by calling `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#cancel`. Due to multi-threading, it is possible that the cancel operation is not successful, and any [Unity coroutine](https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#use-a-unity-coroutine) may successfully resume execution regardless.

<br />

Details Template Parameters `T` The type of the async task result.

## Summary

### Inheritance

Inherits from: [`UnityEngine::CustomYieldInstruction`](https://docs.unity3d.com/ScriptReference/CustomYieldInstruction.html)

| ### Properties ||
|---|---|
| `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#result` | `T` Gets the result, if the operation is done. |
| `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#state` | `https://developers.google.com/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate` Gets the `https://developers.google.com/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate` associated with this promise. |

| ### Public functions ||
|---|---|
| `https://developers.google.com/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/Internal/InterruptiblePromise-T-#cancel()` | `void` Cancels execution of this promise if it's still pending. |

## Properties

### Result

```c#
T Result
```
Gets the result, if the operation is done.

### State

```c#
PromiseState State
```
Gets the `https://developers.google.com/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate` associated with this promise.

Used to determine if the promise is still waiting for the result.

## Public functions

### Cancel

```c#
void Cancel()
```
Cancels execution of this promise if it's still pending.