public static Task <Result <T> > Bind <T>(this Task <Result> sourceTask,
                                           Func <CancellationToken, Task <T> > asyncFactory, CancellationToken cancellationToken)
 => sourceTask
 .ContinueWith(task => task.Exception == null
             ? task.IsCanceled
                 ? FailFactory.GenericCanceledTask <T>(task)
                 : task.Result.Bind(asyncFactory, cancellationToken)
             : FailFactory.GenericExceptionTask <T>(task.Exception))
 .Unwrap();
Пример #2
0
 public static Task <Result <TMapped> > Bind <T, TMapped>(this Task <Result <T> > sourceTask,
                                                          Func <T, Task <TMapped> > asyncMapper)
 => sourceTask
 .ContinueWith(task => task.Exception == null
             ? task.IsCanceled
                 ? FailFactory.GenericCanceledTask <TMapped>(task)
                 : task.Result
               .Bind(asyncMapper)
             : FailFactory.GenericExceptionTask <TMapped>(task.Exception))
 .Unwrap();
Пример #3
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);
Пример #4
0
 public static Task <Result <TMapped> > Bind <T, TMapped>(this Result <T> result, Func <T, Task <TMapped> > asyncMapper)
 => result.Successful
         ? asyncMapper(((Success <T>)result).Value)
 .ThenWrapAsResult()
         : FailFactory.GenericExceptionTask <TMapped>(((Fail <T>)result).Exception);