using System.Threading.Tasks; using System.Collections; using UnityEngine; namespace PashaBibko.PenguinChase.Extensions { public sealed class Result { public T Value { get; set; } } public static class TaskExtensions { public static IEnumerator Await(this Task task) { // Waits until the task is completed while (!task.IsCompleted) { yield return null; } if (task.IsFaulted) { Debug.LogError($"Task failed: [{task.Exception?.InnerException?.Message}]"); } } public static IEnumerator Await(this Task task, Result result) where T : class { // Waits until the task is completed while (!task.IsCompleted) { yield return null; } if (task.IsFaulted) { Debug.LogError($"Task failed: [{task.Exception?.InnerException?.Message}]"); } // Has to return the value like this because of the wonders of C# result.Value = task.Result; } } }