Search Results for

    Show / Hide Table of Contents

    Class Coroutines

    A class providing coroutine helpers.

    Inheritance
    System.Object
    Coroutines
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: IPA.Utilities.Async
    Assembly: IPA.Loader.dll
    Syntax
    public static class Coroutines

    Methods

    | Improve this Doc View Source

    AsTask(IEnumerator)

    Binds a System.Threading.Tasks.Task to a Unity coroutine, capturing exceptions as well as the coroutine call stack.

    Declaration
    public static Task AsTask(IEnumerator coroutine)
    Parameters
    Type Name Description
    System.Collections.IEnumerator coroutine

    the coroutine to bind to a task

    Returns
    Type Description
    System.Threading.Tasks.Task

    a System.Threading.Tasks.Task that completes when coroutine completes, and fails when it throws

    Remarks

    This may be called off of the Unity main thread. If it is, the coroutine start will be scheduled using the default UnityMainThreadTaskScheduler and will be run on the main thread as required by Unity.

    Unity provides a handful of coroutine helpers that are not System.Collections.IEnumerables. Most of these are not terribly helpful on their own, however UnityEngine.WaitForSeconds may be. Instead, prefer to use the typical .NET System.Threading.Tasks.Task.Wait(System.TimeSpan) or similar overloads, or use UnityEngine.WaitForSecondsRealtime.

    | Improve this Doc View Source

    WaitForTask(Task)

    Stalls the coroutine until task completes, faults, or is canceled.

    Declaration
    public static IEnumerator WaitForTask(Task task)
    Parameters
    Type Name Description
    System.Threading.Tasks.Task task

    the System.Threading.Tasks.Task to wait for

    Returns
    Type Description
    System.Collections.IEnumerator

    a coroutine waiting for the given task

    | Improve this Doc View Source

    WaitForTask(Task, Boolean)

    Stalls the coroutine until task completes, faults, or is canceled.

    Declaration
    public static IEnumerator WaitForTask(Task task, bool throwOnFault = false)
    Parameters
    Type Name Description
    System.Threading.Tasks.Task task

    the System.Threading.Tasks.Task to wait for

    System.Boolean throwOnFault

    whether or not to throw if the task faulted

    Returns
    Type Description
    System.Collections.IEnumerator

    a coroutine waiting for the given task

    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX