[Feature Request] GetCancellationTokenOnDisable and Multiple await on same UniTask
See original GitHub issueHey, Just added this issue because I want to confirm few things
GetCancellationTokenOnDisable
- Is there any reason or issue It’s not available,
- For now, we can use UniRx OnDisableAsObservable to run this?
Multiple await on the Same UniTask
This code doesn’t work and throws an exception
public class Test
{
UniTask? process;
public async UniTask Execute()
{
if (!process.HasValue)
{
process = CreateProcess();
}
await process.Value;
}
}
public class TestRunner
{
public void OnEnable()
{
var test = new Test();
test.Execute().Forget();
test.Execute().Forget(); // This will throw a exception
}
}
This code works fine
public class Test
{
Task process;
public async Task Execute()
{
if (process == null)
{
process = CreateProcess();
}
await process;
}
}
public class TestRunner
{
public void OnEnable()
{
var test = new Test();
test.Execute().Forget();
test.Execute().Forget(); // This will throw a exception
}
}
Is there a reason behind this other then UniTask is struct and Task is class?
BTW, Thanks for such a beautiful implementation, really helpful on mobile development, Only hope Unity learn something from this
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
UniTask.WhenAny can't be called multiple times for the ...
I'm trying to use UniTask.WhenAny to maintain a queue of tasks. I need to be notified every time one of the tasks completes....
Read more >Cysharp/UniTask: Provides an efficient allocation ...
Yield(without CancellationToken) is a special type, returns YieldAwaitable and runs on YieldRunner. It is the most lightweight and fastest. AsyncOperation is ...
Read more >Suspend multiple async/await function calls until 1 network ...
When my token expires, I want to send 1 token refresh network call to my backend even if multiple tasks fail and request...
Read more >UniTask v2 — Zero Allocation async/await for Unity, with ...
As a limitation, all UniTask objects cannot await twice, as they automatically return to the pool when the await completes. This constraint is ......
Read more >Can we have multiple await calls inside an Async function ...
I have a function defined as below: private async Task ... Is this the right way to have multiple await calls inside one...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the help. It works now as expected 😃