Пример #1
0
 public static Task <Result> Bind(this Task <Result> sourceTask, Action effect)
 => sourceTask
 .ContinueWith(task => task.Exception == null
             ? task.IsCanceled
                 ? FailFactory.ValuelessCanceled(task)
                 : task.Result.Bind(effect)
             : FailFactory.ValuelessException(task.Exception));
 public static Task <Result> Bind <T>(this Task <Result <T> > sourceTask,
                                      Action <T, CancellationToken> effect, CancellationToken cancellationToken)
 => sourceTask
 .ContinueWith(task => task.Exception == null
             ? task.IsCanceled
                 ? FailFactory.ValuelessCanceled(task)
                 : task.Result.Bind(effect, cancellationToken)
             : FailFactory.ValuelessException(task.Exception)
               );
Пример #3
0
 public static Task <Result> Bind(this Result result, Func <Task> asyncEffect)
 => result.Successful
         ? asyncEffect()
 .ContinueWith(task => task.Exception == null
                 ? task.IsCanceled
                     ? FailFactory.ValuelessCanceled(task)
                     : Result.Success
                 : FailFactory.ValuelessException(task.Exception))
         : Task
 .FromResult(result);
Пример #4
0
 public static Task <Result> Bind(this Result result, Func <CancellationToken, Task> asyncEffect,
                                  CancellationToken cancellationToken)
 => result.Successful
         ? asyncEffect(cancellationToken)
 // ReSharper disable once MethodSupportsCancellation
 .ContinueWith(task => task.Exception == null
                 ? task.IsCanceled
                     ? FailFactory.ValuelessCanceled(task)
                     : Result.Success
                 : FailFactory.ValuelessException(task.Exception))
         : Task
 .FromResult(result);
Пример #5
0
 public static Task <Result> ThenWrapAsResult(this Task sourceTask)
 => sourceTask
 .ContinueWith(task => task.Exception ?? (task.IsCanceled
             ? FailFactory.ValuelessCanceled(task)
             : Result.Success)
               );