How to mimic TaskStatus.Running from C# Tasks in UniTasks?
Opened this issue · 3 comments
Hey, wonderful package, you deserve a monument for this.
I'm just wondering, UniTask have a lot of UniTaskStatus options, but I'm missing the equivalent to TaskStatus.Running
, why? How can I try to know if a Task is Running? The only way I can think of is to do:
public static bool IsRunning(this UniTask uniTask)
{
return uniTask.Status is not (UniTaskStatus.Canceled and UniTaskStatus.Faulted and UniTaskStatus.Pending and UniTaskStatus.Succeeded);
}
But this, by default it's imposible, cause there's no any other state :/
Could you suggest a better way? I need this to also work with Defered tasks, and this issue makes me think that maybe accessing and comparing Status is not the best way :(
Since UniTask may always be returned to the pool, checking with IsRunning and then performing some execution may not be safe.
Because this safety cannot be guaranteed, we cannot officially provide checking points.
This is a trade-off that comes with the allocation-free design.
Thanks for the quick answer.
Understood, it is a limitation of the framework.
Are you aware about any workaround, knowing the current limitation of the system?
Could be a good idea to reflect that on the Readme? (I can do it myself if you prefer)
I oppose including Status in the ReadMe since it's primarily an internal flag that should only be used when absolutely necessary by people who understand the internal workings.