From 27ef05325282d6037300a87900d26bfca9212863 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Sun, 25 Aug 2024 22:23:58 +0900 Subject: [PATCH] Update docs --- Dalamud/Utility/TaskExtensions.cs | 42 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/Dalamud/Utility/TaskExtensions.cs b/Dalamud/Utility/TaskExtensions.cs index 2855511a1..f03a9e9e9 100644 --- a/Dalamud/Utility/TaskExtensions.cs +++ b/Dalamud/Utility/TaskExtensions.cs @@ -63,20 +63,34 @@ public static class TaskExtensions #pragma warning restore RS0030 } - /// Ignores any exceptions thrown from the task. - /// Task to ignore exceptions. - /// A task that completes when completes in any state. - public static async Task SuppressException(this Task task) - { - try - { - await task; - } - catch - { - // ignore - } - } + /// Creates a new that resolves when completes, ignoring + /// exceptions thrown from the task, if any. + /// Task to await and ignore exceptions on failure. + /// A that completes successfully when completes in any state. + /// + /// Awaiting the returned will always complete without exceptions, but awaiting + /// will throw exceptions if it fails, even after this function is called. + /// + /// + /// Wrong use of this function + /// + /// var task = TaskThrowingException(); + /// task.SuppressException(); + /// await TaskThrowingException(); // This line will throw. + /// + /// + /// + /// Correct use of this function, if waiting for the task + /// await TaskThrowingException().SuppressException(); + /// + /// + /// Fire-and-forget
+ /// If not interested in the execution state of Task (fire-and-forget), simply calling this function will do. + /// This function consumes the task's exception, so that it won't bubble up on later garbage collection. + /// TaskThrowingException().SuppressException(); + ///
+ ///
+ public static Task SuppressException(this Task task) => task.ContinueWith(static r => r.Exception); private static bool IsWaitingValid(Task task) {