feat: added WaitForTask yield
This commit is contained in:
35
Engine.Core/Systems/Yields/WaitForTaskYield.cs
Normal file
35
Engine.Core/Systems/Yields/WaitForTaskYield.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user