Exemple #1
0
        protected async Task <DataResult <T> > CallAsyncWithRetry <T>(Func <Task <DataResult <T> > > actionInvoker, CancellationToken?cancellationToken = null, TimeSpan?retryInterval = null, int retryCount = 3)
        {
            IRetryBuilder <T> retryBuilder = new RetryBuilder <T>();

            retryBuilder.BuildActionInvoker(actionInvoker);
            retryBuilder.BuildCancellationToken(cancellationToken.GetValueOrDefault());
            retryBuilder.BuildRetryCount(retryCount);
            retryBuilder.BuildRetryInterval(retryInterval.HasValue ? retryInterval.Value : TimeSpan.FromSeconds(3));

            var retryPolicy = new AsyncRetryPolicy
            {
                RetryCount    = retryBuilder.Parameter.RetryCount,
                RetryInterval = retryBuilder.Parameter.RetryInterval
            };

            var result = await asyncRetry.DoAsync(actionInvoker, retryPolicy, retryBuilder.Parameter.CancellationToken);

            return(result);
        }
Exemple #2
0
        public async Task <DataResult <T> > CallAsync <T>(Func <Task <DataResult <T> > > actionInvoker) where T : class
        {
            var result = await asyncRetry.DoAsync(actionInvoker);

            return(result);
        }