private static Task <Result <T> > ContinuationFactory <T>(Task <T> sourceTask)
 => sourceTask
 .ContinueWith(task => task.Exception == null
             ? task.IsCanceled
                 ? FailFactory.GenericCanceled <T>(task)
                 : new Success <T>(task.Result)
             : FailFactory.GenericException <T>(task.Exception));
 public static Task <Result <T> > Bind <T>(this Task <Result> sourceTask, Func <T> factory)
 => sourceTask
 .ContinueWith(task => task.Exception == null
             ? task.IsCanceled
                 ? FailFactory.GenericCanceled <T>(task)
                 : task.Result.Bind(factory)
             : FailFactory.GenericException <T>(task.Exception)
               );
示例#3
0
 public static Task <Result <T> > ThenWrapAsResult <T>(this Task <T> sourceTask)
 => sourceTask
 .ContinueWith(task => task.Exception == null
             ? task.IsCanceled
                 ? FailFactory.GenericCanceled <T>(task)
                 : task.Result.AsSuccess()
             : FailFactory.GenericException <T>(task.Exception)
               );
示例#4
0
 public static Task <Result <TMapped> > Bind <T, TMapped>(this Result <T> result,
                                                          Func <T, CancellationToken, Task <TMapped> > asyncMapper, CancellationToken cancellationToken)
 => result.Successful
         ? asyncMapper(result, cancellationToken)
 // ReSharper disable once MethodSupportsCancellation
 .ContinueWith(task =>
               task.Exception == null
                     ? task.IsCanceled
                         ? FailFactory.GenericCanceled <TMapped>(task)
                         : task.Result.AsSuccess()
                     : FailFactory.GenericException <TMapped>(task.Exception))
         : FailFactory.GenericExceptionTask <TMapped>(((Fail <T>)result).Exception);
示例#5
0
 public static Result <TMapped> Bind <T, TMapped>(this Result <T> result,
                                                  Func <T, CancellationToken, TMapped> mapper, CancellationToken cancellationToken = default)
 => result.Successful
         ? Execute.Safely(((Success <T>)result).Value, mapper, cancellationToken)
         : FailFactory.GenericException <TMapped>(((Fail <T>)result).Exception);
示例#6
0
 public static Result <TMapped> Bind <T, TMapped>(this Result <T> result, Func <T, TMapped> mapper)
 => result.Successful
         ? Execute.Safely(((Success <T>)result).Value, mapper)
         : FailFactory.GenericException <TMapped>(((Fail <T>)result).Exception);