From 2e1b322162d999b12e4079c52dd52fae4cfeaa67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuzhan=20Y=C4=B1lmaz?= Date: Wed, 11 Jun 2025 17:33:34 +0300 Subject: [PATCH] Fix error suppression logic --- .../Runtime/GameBootStrapper.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Boot/Assets/Scripts/GameBootStrapper.Unity/Runtime/GameBootStrapper.cs b/Boot/Assets/Scripts/GameBootStrapper.Unity/Runtime/GameBootStrapper.cs index ebbbf2f..eb85535 100644 --- a/Boot/Assets/Scripts/GameBootStrapper.Unity/Runtime/GameBootStrapper.cs +++ b/Boot/Assets/Scripts/GameBootStrapper.Unity/Runtime/GameBootStrapper.cs @@ -14,7 +14,7 @@ public static async Task RunTasks(Action progress, BootStr params Func[] tasks) { ctx.totalTaskCount = tasks.Length; - var parallelTasks = new List>(); + var parallelTasks = new List<(Task Task, bool Suppress)>(); foreach (var fn in tasks) { var meta = fn.Method.GetCustomAttribute(); @@ -25,11 +25,11 @@ public static async Task RunTasks(Action progress, BootStr { case BootStrapTaskType.Sequential: var result = await ExecuteTaskAsync(fn, ctx, progress, meta); - if (!result.Success) + if (!result.Success && !meta.SuppressError) return result; break; case BootStrapTaskType.Parallel: - parallelTasks.Add(ExecuteTaskAsync(fn, ctx, progress, meta)); + parallelTasks.Add((ExecuteTaskAsync(fn, ctx, progress, meta), meta.SuppressError)); break; case BootStrapTaskType.Forget: _ = ExecuteTaskAsync(fn, ctx, progress, meta); @@ -37,12 +37,13 @@ public static async Task RunTasks(Action progress, BootStr } } - if (!parallelTasks.Any()) + if (!parallelTasks.Any()) return new BootStrapResult() { Success = true }; - - var parallelTaskResults = await Task.WhenAll(parallelTasks); - var failedTaskResult = parallelTaskResults.FirstOrDefault(r => !r.Success); - + + var parallelTaskResults = await Task.WhenAll(parallelTasks.Select(p => p.Task)); + var zipped = parallelTaskResults.Zip(parallelTasks, (result, info) => new { result, info.Suppress }); + var failedTaskResult = zipped.FirstOrDefault(p => !p.result.Success && !p.Suppress)?.result; + return failedTaskResult ?? new BootStrapResult { Success = true }; } @@ -51,19 +52,16 @@ private static async Task ExecuteTaskAsync(Func Task.FromResult(task(ctx)), cancellationToken: ctx.ct) + var result = await Task.Run(() => task(ctx), ctx.ct) .TimeOut(meta.Timeout, ctx.ct); ctx.IncrementCompletedTaskCount(); progress?.Invoke(CalculateProgressPercentage(ctx)); Debug.Log($"Step {task.Method.Name} completed with result: {result.Success}"); - if(meta.SuppressError) - return new BootStrapResult(){ Success = true , Message = "Suppressed error"}; - - if (!result.Success) + if (!result.Success && !meta.SuppressError) ctx.cancellationTokenSource.Cancel(); - + return result; } catch (Exception ex)