-
Notifications
You must be signed in to change notification settings - Fork 0
Task Extensions
Andrzej Kebab edited this page Feb 4, 2024
·
1 revision
Converts the Task into an IEnumerator for Unity coroutine usage.
Task myTask = // initialize your Task
IEnumerator coroutine = myTask.AsCoroutine();Parameters:
-
task: TheTaskto convert.
Returns:
-
coroutine: AnIEnumeratorrepresentation of theTask.
Usage:
async void MyMethod()
{
Task myTask = SomeAsyncMethod();
yield return myTask.AsCoroutine();
// Continue with the rest of the coroutine logic...
}Note:
- When used on a faulted
Task,GetResult()will propagate the original exception. See: Task Exception Handling in .NET 4.5