Cysharp/UniTask

Tasks do not complete in the order they were started

JohannesPaivinen opened this issue · 1 comments

Hello,

We're seeing that UniTask tasks do not maintain their execution order throughout execution. For example, this code:

   void Start()
    {
        for (var i = 0; i < 3; i++)
            UpdateAsync(i).Forget();
    }

    private async UniTask UpdateAsync(int id)
    {
        Debug.Log($"{id} started");
        await UniTask.Delay(500);
        Debug.Log($"{id} completed");
    }

Would start tasks 0-1-2 but complete 0-2-1.

This is due to how UniTask fills the gaps in item lists in PlayerLoopRunner when tasks complete.

It would simplify our code a lot if we would be able to rely on the execution order being maintained. Is there any way to make this happen in UniTask?

Writing the program dependent on the order of execution is not a good practice in general. Why would you need to complicate your code?