Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mimic TaskStatus.Running from C# Tasks in UniTasks? #643

Open
EricBatlleTripledot opened this issue Dec 12, 2024 · 3 comments
Open

Comments

@EricBatlleTripledot
Copy link

EricBatlleTripledot commented Dec 12, 2024

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 :(

@neuecc
Copy link
Member

neuecc commented Dec 13, 2024

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.

@EricBatlleTripledot
Copy link
Author

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)

@neuecc
Copy link
Member

neuecc commented Dec 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants