docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Promise<T>

    A Promise is used for operations that retrieve data asynchronously. Use this object to determine the status of the operation (that is, whether it has completed), and the resulting data.

    Inheritance
    object
    CustomYieldInstruction
    Promise<T>
    Implements
    IEnumerator
    Inherited Members
    CustomYieldInstruction.MoveNext()
    CustomYieldInstruction.Reset()
    CustomYieldInstruction.Current
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: UnityEngine.XR.ARSubsystems
    Assembly: solution.dll
    Syntax
    public abstract class Promise<T> : CustomYieldInstruction, IEnumerator
    Type Parameters
    Name Description
    T

    The type of information the asynchronous operation retrieves.

    Remarks

    Since Promise<T> derives from CustomYieldInstruction, you can yield return on a Promise in a coroutine. If you prefer not to use the Promise as a coroutine, you can manually check keepWaiting to determine if the operation has completed. Once the operation is complete, you can get the resulting value from result.

    Examples

    Example usage in a coroutine:

    IEnumerator MyCoroutine()
    {
        var promise = GetDataAsync();
        yield return promise;
        Debug.LogFormat("Operation complete. Result = {0}", promise.result);
    }

    Properties

    Name Description
    keepWaiting

    Will return true as long as the operation has not yet completed.

    result

    The result of the asynchronous operation. Not valid until keepWaiting returns false.

    Methods

    Name Description
    CreateResolvedPromise(T)

    Creates a resolved promise (that is, a promise that is already complete).

    OnKeepWaiting()

    Invoked whenever keepWaiting is queried. Implement this to perform per-frame updates.

    Resolve(T)

    The creator of the Promise<T> should call this when the asynchronous operation completes.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)