@@ -365,7 +365,12 @@ public async UniTask Update()
365365 arr [ i ] = sequence [ i ] . OnInit ( this ) ;
366366 }
367367
368- await ExecuteTasks ( arr , 0 , sequence . Count ) ;
368+ var task = ExecuteTasks ( arr , 0 , sequence . Count ) ;
369+ if ( task . Status != UniTaskStatus . Succeeded )
370+ {
371+ await task ;
372+ }
373+
369374 ArrayPool < UniTask > . Shared . Return ( arr ) ;
370375 }
371376
@@ -384,7 +389,12 @@ public async UniTask Update()
384389 arr [ i ] = sequence [ i ] . Update ( this , OnError ) ;
385390 }
386391
387- await ExecuteTasks ( arr , 0 , sequence . Count ) ;
392+ var task = ExecuteTasks ( arr , 0 , sequence . Count ) ;
393+ if ( task . Status != UniTaskStatus . Succeeded )
394+ {
395+ await task ;
396+ }
397+
388398 ArrayPool < UniTask > . Shared . Return ( arr ) ;
389399 }
390400 }
@@ -407,35 +417,79 @@ private async UniTask ExecuteTasks(UniTask[] tasks, int actualStartIndex, int ac
407417 // If count is 1, just await directly to avoid overhead
408418 else if ( actualCount == 1 )
409419 {
410- await tasks [ actualStartIndex ] ;
420+ ref var task = ref tasks [ actualStartIndex ] ;
421+ if ( task . Status != UniTaskStatus . Succeeded )
422+ {
423+ await task ;
424+ }
411425 }
412426 // Else if count is 2, unroll the loop for slight performance gain
413427 else if ( actualCount == 2 )
414428 {
415- await tasks [ actualStartIndex ] ;
416- await tasks [ actualStartIndex + 1 ] ;
429+ ref var task0 = ref tasks [ actualStartIndex ] ;
430+ if ( task0 . Status != UniTaskStatus . Succeeded )
431+ {
432+ await task0 ;
433+ }
434+ ref var task1 = ref tasks [ actualStartIndex + 1 ] ;
435+ if ( task1 . Status != UniTaskStatus . Succeeded )
436+ {
437+ await task1 ;
438+ }
417439 }
418440 // Else if count is 3, unroll the loop for slight performance gain
419441 else if ( actualCount == 3 )
420442 {
421- await tasks [ actualStartIndex ] ;
422- await tasks [ actualStartIndex + 1 ] ;
423- await tasks [ actualStartIndex + 2 ] ;
443+ ref var task0 = ref tasks [ actualStartIndex ] ;
444+ if ( task0 . Status != UniTaskStatus . Succeeded )
445+ {
446+ await task0 ;
447+ }
448+ ref var task1 = ref tasks [ actualStartIndex + 1 ] ;
449+ if ( task1 . Status != UniTaskStatus . Succeeded )
450+ {
451+ await task1 ;
452+ }
453+ ref var task2 = ref tasks [ actualStartIndex + 2 ] ;
454+ if ( task2 . Status != UniTaskStatus . Succeeded )
455+ {
456+ await task2 ;
457+ }
424458 }
425459 // Else if count is 4, unroll the loop for slight performance gain
426460 else if ( actualCount == 4 )
427461 {
428- await tasks [ actualStartIndex ] ;
429- await tasks [ actualStartIndex + 1 ] ;
430- await tasks [ actualStartIndex + 2 ] ;
431- await tasks [ actualStartIndex + 3 ] ;
462+ ref var task0 = ref tasks [ actualStartIndex ] ;
463+ if ( task0 . Status != UniTaskStatus . Succeeded )
464+ {
465+ await task0 ;
466+ }
467+ ref var task1 = ref tasks [ actualStartIndex + 1 ] ;
468+ if ( task1 . Status != UniTaskStatus . Succeeded )
469+ {
470+ await task1 ;
471+ }
472+ ref var task2 = ref tasks [ actualStartIndex + 2 ] ;
473+ if ( task2 . Status != UniTaskStatus . Succeeded )
474+ {
475+ await task2 ;
476+ }
477+ ref var task3 = ref tasks [ actualStartIndex + 3 ] ;
478+ if ( task3 . Status != UniTaskStatus . Succeeded )
479+ {
480+ await task3 ;
481+ }
432482 }
433483 else
434484 {
435485 // Sequential execution (zero allocation)
436486 for ( int i = actualStartIndex ; i < actualStartIndex + actualCount ; i ++ )
437487 {
438- await tasks [ i ] ;
488+ ref var task = ref tasks [ i ] ;
489+ if ( task . Status != UniTaskStatus . Succeeded )
490+ {
491+ await task ;
492+ }
439493 }
440494 }
441495 }
0 commit comments