| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using System.Collections; |
| | 6 | | using System.Threading.Tasks; |
| | 7 | |
|
| | 8 | | namespace GDX.Threading |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// <see cref="Task" /> Based Extension Methods |
| | 12 | | /// </summary> |
| | 13 | | public static class TaskExtensions |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Wraps a <see cref="Task" /> for use in a coroutine. |
| | 17 | | /// </summary> |
| | 18 | | /// <remarks>Don't use coroutines.</remarks> |
| | 19 | | /// <param name="task">An established <see cref="Task" />.</param> |
| | 20 | | /// <returns>An <see cref="IEnumerator" /> for use with coroutines.</returns> |
| | 21 | | public static IEnumerator AsIEnumerator(this Task task) |
| 20 | 22 | | { |
| 224 | 23 | | while (!task.IsCompleted) |
| 204 | 24 | | { |
| 204 | 25 | | yield return null; |
| 204 | 26 | | } |
| 20 | 27 | | } |
| | 28 | | } |
| | 29 | | } |