question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] GetCancellationTokenOnDisable and Multiple await on same UniTask

See original GitHub issue

Hey, 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:closed
  • Created 3 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
neuecccommented, Oct 27, 2020
UniTaskCompletionSource completeSignal = new UniTaskCompletionSource();

DownloadSomething()
{
    try
    {
        await ....
    }
    finally
    {
        completeSignal.TrySetResult();
    }
}
0reactions
Inspyrocommented, Oct 27, 2020

Thanks for the help. It works now as expected 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found