36 lines
945 B
C#
36 lines
945 B
C#
using System.Threading.Tasks;
|
|
|
|
using static Engine.Core.WaitForTaskYield;
|
|
|
|
namespace Engine.Core;
|
|
|
|
public class WaitForTaskYield(Task task, TaskCompletionStatus completionStatus = TaskCompletionStatus.Either) : ICoroutineYield
|
|
{
|
|
public bool Yield()
|
|
{
|
|
switch (completionStatus)
|
|
{
|
|
case TaskCompletionStatus.Successful:
|
|
if (task.IsCanceled)
|
|
throw new("Task has been canceled.");
|
|
if (task.IsFaulted)
|
|
throw new("Task has faulted.");
|
|
return task.IsCompletedSuccessfully;
|
|
|
|
case TaskCompletionStatus.Failed:
|
|
if (task.IsCompletedSuccessfully)
|
|
throw new("Task was completed successfully.");
|
|
return task.IsFaulted;
|
|
}
|
|
|
|
return task.IsCompleted;
|
|
}
|
|
|
|
public enum TaskCompletionStatus
|
|
{
|
|
Either,
|
|
Successful,
|
|
Failed
|
|
}
|
|
}
|