Interface IPromise<PromisedT> | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Interface IPromise<PromisedT>

    Implements a C# promise. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise

    Namespace: RSG
    Syntax
    public interface IPromise<PromisedT>
    Type Parameters
    Name Description
    PromisedT

    Properties

    Id

    Gets the id of the promise, useful for referencing the promise during runtime.

    Declaration
    int Id { get; }
    Property Value
    Type Description
    System.Int32

    isCompleted

    Declaration
    bool isCompleted { get; }
    Property Value
    Type Description
    System.Boolean

    Methods

    Catch(Action<Exception>)

    Handle errors for the promise.

    Declaration
    IPromise Catch(Action<Exception> onRejected)
    Parameters
    Type Name Description
    System.Action<System.Exception> onRejected
    Returns
    Type Description
    IPromise

    Catch(Func<Exception, PromisedT>)

    Handle errors for the promise.

    Declaration
    IPromise<PromisedT> Catch(Func<Exception, PromisedT> onRejected)
    Parameters
    Type Name Description
    System.Func<System.Exception, PromisedT> onRejected
    Returns
    Type Description
    IPromise<PromisedT>

    ContinueWith(Func<IPromise>)

    Add a callback that chains a non-value promise. ContinueWith callbacks will always be called, even if any preceding promise is rejected, or encounters an error. The state of the returning promise will be based on the new non-value promise, not the preceding (rejected or resolved) promise.

    Declaration
    IPromise ContinueWith(Func<IPromise> onResolved)
    Parameters
    Type Name Description
    System.Func<IPromise> onResolved
    Returns
    Type Description
    IPromise

    ContinueWith<ConvertedT>(Func<IPromise<ConvertedT>>)

    Add a callback that chains a value promise (optionally converting to a different value type). ContinueWith callbacks will always be called, even if any preceding promise is rejected, or encounters an error. The state of the returning promise will be based on the new value promise, not the preceding (rejected or resolved) promise.

    Declaration
    IPromise<ConvertedT> ContinueWith<ConvertedT>(Func<IPromise<ConvertedT>> onComplete)
    Parameters
    Type Name Description
    System.Func<IPromise<ConvertedT>> onComplete
    Returns
    Type Description
    IPromise<ConvertedT>
    Type Parameters
    Name Description
    ConvertedT

    Done()

    Complete the promise. Adds a default error handler.

    Declaration
    void Done()

    Done(Action<PromisedT>)

    Completes the promise. onResolved is called on successful completion. Adds a default error handler.

    Declaration
    void Done(Action<PromisedT> onResolved)
    Parameters
    Type Name Description
    System.Action<PromisedT> onResolved

    Done(Action<PromisedT>, Action<Exception>)

    Completes the promise. onResolved is called on successful completion. onRejected is called on error.

    Declaration
    void Done(Action<PromisedT> onResolved, Action<Exception> onRejected)
    Parameters
    Type Name Description
    System.Action<PromisedT> onResolved
    System.Action<System.Exception> onRejected

    Finally(Action)

    Add a finally callback. Finally callbacks will always be called, even if any preceding promise is rejected, or encounters an error. The returned promise will be resolved or rejected, as per the preceding promise.

    Declaration
    IPromise<PromisedT> Finally(Action onComplete)
    Parameters
    Type Name Description
    System.Action onComplete
    Returns
    Type Description
    IPromise<PromisedT>

    Progress(Action<Single>)

    Add a progress callback. Progress callbacks will be called whenever the promise owner reports progress towards the resolution of the promise.

    Declaration
    IPromise<PromisedT> Progress(Action<float> onProgress)
    Parameters
    Type Name Description
    System.Action<System.Single> onProgress
    Returns
    Type Description
    IPromise<PromisedT>

    Then(Action<PromisedT>)

    Add a resolved callback.

    Declaration
    IPromise Then(Action<PromisedT> onResolved)
    Parameters
    Type Name Description
    System.Action<PromisedT> onResolved
    Returns
    Type Description
    IPromise

    Then(Action<PromisedT>, Action<Exception>)

    Add a resolved callback and a rejected callback.

    Declaration
    IPromise Then(Action<PromisedT> onResolved, Action<Exception> onRejected)
    Parameters
    Type Name Description
    System.Action<PromisedT> onResolved
    System.Action<System.Exception> onRejected
    Returns
    Type Description
    IPromise

    Then(Action<PromisedT>, Action<Exception>, Action<Single>)

    Add a resolved callback, a rejected callback and a progress callback.

    Declaration
    IPromise Then(Action<PromisedT> onResolved, Action<Exception> onRejected, Action<float> onProgress)
    Parameters
    Type Name Description
    System.Action<PromisedT> onResolved
    System.Action<System.Exception> onRejected
    System.Action<System.Single> onProgress
    Returns
    Type Description
    IPromise

    Then(Func<PromisedT, IPromise>)

    Add a resolved callback that chains a non-value promise.

    Declaration
    IPromise Then(Func<PromisedT, IPromise> onResolved)
    Parameters
    Type Name Description
    System.Func<PromisedT, IPromise> onResolved
    Returns
    Type Description
    IPromise

    Then(Func<PromisedT, IPromise>, Action<Exception>)

    Add a resolved callback and a rejected callback. The resolved callback chains a non-value promise.

    Declaration
    IPromise Then(Func<PromisedT, IPromise> onResolved, Action<Exception> onRejected)
    Parameters
    Type Name Description
    System.Func<PromisedT, IPromise> onResolved
    System.Action<System.Exception> onRejected
    Returns
    Type Description
    IPromise

    Then(Func<PromisedT, IPromise>, Action<Exception>, Action<Single>)

    Add a resolved callback, a rejected callback and a progress callback. The resolved callback chains a non-value promise.

    Declaration
    IPromise Then(Func<PromisedT, IPromise> onResolved, Action<Exception> onRejected, Action<float> onProgress)
    Parameters
    Type Name Description
    System.Func<PromisedT, IPromise> onResolved
    System.Action<System.Exception> onRejected
    System.Action<System.Single> onProgress
    Returns
    Type Description
    IPromise

    Then<ConvertedT>(Func<PromisedT, ConvertedT>)

    Return a new promise with a different value. May also change the type of the value.

    Declaration
    IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, ConvertedT> transform)
    Parameters
    Type Name Description
    System.Func<PromisedT, ConvertedT> transform
    Returns
    Type Description
    IPromise<ConvertedT>
    Type Parameters
    Name Description
    ConvertedT

    Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>>)

    Add a resolved callback that chains a value promise (optionally converting to a different value type).

    Declaration
    IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>> onResolved)
    Parameters
    Type Name Description
    System.Func<PromisedT, IPromise<ConvertedT>> onResolved
    Returns
    Type Description
    IPromise<ConvertedT>
    Type Parameters
    Name Description
    ConvertedT

    Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>>, Func<Exception, IPromise<ConvertedT>>)

    Add a resolved callback and a rejected callback. The resolved callback chains a value promise (optionally converting to a different value type).

    Declaration
    IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>> onResolved, Func<Exception, IPromise<ConvertedT>> onRejected)
    Parameters
    Type Name Description
    System.Func<PromisedT, IPromise<ConvertedT>> onResolved
    System.Func<System.Exception, IPromise<ConvertedT>> onRejected
    Returns
    Type Description
    IPromise<ConvertedT>
    Type Parameters
    Name Description
    ConvertedT

    Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>>, Func<Exception, IPromise<ConvertedT>>, Action<Single>)

    Add a resolved callback, a rejected callback and a progress callback. The resolved callback chains a value promise (optionally converting to a different value type).

    Declaration
    IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>> onResolved, Func<Exception, IPromise<ConvertedT>> onRejected, Action<float> onProgress)
    Parameters
    Type Name Description
    System.Func<PromisedT, IPromise<ConvertedT>> onResolved
    System.Func<System.Exception, IPromise<ConvertedT>> onRejected
    System.Action<System.Single> onProgress
    Returns
    Type Description
    IPromise<ConvertedT>
    Type Parameters
    Name Description
    ConvertedT

    ThenAll(Func<PromisedT, IEnumerable<IPromise>>)

    Chain an enumerable of promises, all of which must resolve. Converts to a non-value promise. The resulting promise is resolved when all of the promises have resolved. It is rejected as soon as any of the promises have been rejected.

    Declaration
    IPromise ThenAll(Func<PromisedT, IEnumerable<IPromise>> chain)
    Parameters
    Type Name Description
    System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise>> chain
    Returns
    Type Description
    IPromise

    ThenAll<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>>)

    Chain an enumerable of promises, all of which must resolve. Returns a promise for a collection of the resolved results. The resulting promise is resolved when all of the promises have resolved. It is rejected as soon as any of the promises have been rejected.

    Declaration
    IPromise<IEnumerable<ConvertedT>> ThenAll<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>> chain)
    Parameters
    Type Name Description
    System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise<ConvertedT>>> chain
    Returns
    Type Description
    IPromise<System.Collections.Generic.IEnumerable<ConvertedT>>
    Type Parameters
    Name Description
    ConvertedT

    ThenRace(Func<PromisedT, IEnumerable<IPromise>>)

    Takes a function that yields an enumerable of promises. Converts to a non-value promise. Returns a promise that resolves when the first of the promises has resolved. Yields the value from the first promise that has resolved.

    Declaration
    IPromise ThenRace(Func<PromisedT, IEnumerable<IPromise>> chain)
    Parameters
    Type Name Description
    System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise>> chain
    Returns
    Type Description
    IPromise

    ThenRace<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>>)

    Takes a function that yields an enumerable of promises. Returns a promise that resolves when the first of the promises has resolved. Yields the value from the first promise that has resolved.

    Declaration
    IPromise<ConvertedT> ThenRace<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>> chain)
    Parameters
    Type Name Description
    System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise<ConvertedT>>> chain
    Returns
    Type Description
    IPromise<ConvertedT>
    Type Parameters
    Name Description
    ConvertedT

    WithName(String)

    Set the name of the promise, useful for debugging.

    Declaration
    IPromise<PromisedT> WithName(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    IPromise<PromisedT>
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023