Ejemplo n.º 1
0
            public async Task <TResult> Operation(CancellationToken cancellationToken)
            {
                var now = DateTime.Now;

                try
                {
                    await _functionProvider.Func <CancellationToken, Task <TResult> >(cancellationToken);

                    int triedTimes = _invocations.Count;
                    if (triedTimes < _transientFaultCount)
                    {
                        switch (_transientFaultFactory.Invoke(triedTimes))
                        {
                        case Exception transientExcepption:
                            throw transientExcepption;

                        case TResult transientResult:
                            return(transientResult);
                        }
                    }

                    return(_result);
                }
                finally
                {
                    _invocations.Add(now);
                }
            }
            public async Task Operation(CancellationToken cancellationToken)
            {
                var now = DateTime.Now;

                try
                {
                    await _functionProvider.Func <CancellationToken, Task>(cancellationToken);

                    int triedTimes = _invocations.Count;
                    if (triedTimes < _transientFaultCount)
                    {
                        throw _transientExceptionFactory.Invoke(triedTimes);
                    }
                }
                finally
                {
                    _invocations.Add(now);
                }
            }