diff --git a/src/TaskExtensions.cs b/src/TaskExtensions.cs index dd19601..e31bf2f 100644 --- a/src/TaskExtensions.cs +++ b/src/TaskExtensions.cs @@ -13,20 +13,11 @@ public static partial class TaskExtensions private static Exception PotentiallyUnwindException(Exception exception) => exception is AggregateException aggregateException ? aggregateException.InnerException ?? exception : exception; - - private static Exception HandleCancellation(this Task task) - { - try - { - T result = task.Result; - - return new Exception("Expected canceled task"); - } - catch (Exception exception) - { - return PotentiallyUnwindException(exception); - } - } + + private static Exception HandleCancellation(Task task) => + task.IsCanceled + ? new TaskCanceledException() + : PotentiallyUnwindException(task.Exception ?? new Exception("Expected canceled task")); /// /// Monadic 'alt'.