You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
811 B

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace IPA.Utilities.Async
  8. {
  9. /// <summary>
  10. /// A class providing coroutine helpers.
  11. /// </summary>
  12. public static class Coroutines
  13. {
  14. /// <summary>
  15. /// Stalls the coroutine until <paramref name="task"/> completes, faults, or is canceled.
  16. /// </summary>
  17. /// <param name="task">the <see cref="Task"/> to wait for</param>
  18. /// <returns>a coroutine waiting for the given task</returns>
  19. public static IEnumerator WaitForTask(Task task)
  20. {
  21. while (!task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
  22. yield return null;
  23. }
  24. }
  25. }