19 lines
432 B
C#
19 lines
432 B
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Engine.Core;
|
|
|
|
public static class CoroutineYieldExtensions
|
|
{
|
|
public static async Task ToTask(this ICoroutineYield coroutineYield, CancellationToken cancellationToken = default)
|
|
{
|
|
while (coroutineYield.Yield())
|
|
{
|
|
if (cancellationToken.IsCancellationRequested)
|
|
return;
|
|
|
|
Thread.Sleep(1);
|
|
}
|
|
}
|
|
}
|