UniTask icon indicating copy to clipboard operation
UniTask copied to clipboard

UniTask.WhenAny

Open fakegood opened this issue 2 years ago • 2 comments

Hello, I would like to ask how can I replicate this Task.WhenAny example with UniTask? I am having trouble with this because I kept running into InvalidOperationException: Already continuation registered, can not await twice or get Status after await. exception.

Specifically this part

int total = 0;
    while (downloadTasks.Any())
    {
        Task<int> finishedTask = await Task.WhenAny(downloadTasks);
        downloadTasks.Remove(finishedTask);
        total += await finishedTask;
    }

fakegood avatar Aug 08 '22 23:08 fakegood

UniTask is similar as ValueTask, does not applicable some samples of Task.

neuecc avatar Aug 09 '22 01:08 neuecc

UniTask is similar as ValueTask, does not applicable some samples of Task.

if I want to do something similar, is there any example you can provide?

fakegood avatar Aug 13 '22 03:08 fakegood

convert to Task(ToTask). However, it is not recommended due to the overhead. You may want to consider a different approach.

neuecc avatar Aug 14 '22 23:08 neuecc