public async Task <PolicyResult <TResult> > ExecuteAndCaptureAsync(Func <Context, CancellationToken, Task <TResult> > action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) { if (_asyncExecutionPolicy == null) { throw new InvalidOperationException( "Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods."); } if (context == null) { throw new ArgumentNullException(nameof(context)); } try { TResult result = await ExecuteAsync(action, context, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); if (ResultPredicates.Any(predicate => predicate(result))) { return(PolicyResult <TResult> .Failure(result, context)); } return(PolicyResult <TResult> .Successful(result, context)); } catch (Exception exception) { return(PolicyResult <TResult> .Failure(exception, GetExceptionType(ExceptionPredicates, exception), context)); } }
public PolicyResult <TResult> ExecuteAndCapture(Func <Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken) { if (_executionPolicy == null) { throw new InvalidOperationException( "Please use the synchronous-defined policies when calling the synchronous Execute (and similar) methods."); } if (context == null) { throw new ArgumentNullException(nameof(context)); } try { TResult result = Execute(action, context, cancellationToken); if (ResultPredicates.Any(predicate => predicate(result))) { return(PolicyResult <TResult> .Failure(result, context)); } return(PolicyResult <TResult> .Successful(result, context)); } catch (Exception exception) { return(PolicyResult <TResult> .Failure(exception, GetExceptionType(ExceptionPredicates, exception), context)); } }