Esempio n. 1
0
        public async Task WithRetry_InvokeAsync()
        {
            var ac = new WithRetryTestClass();

            WithRetry.SetDefaultPolicy(new RetryPolicy(3, TimeSpan.FromSeconds(15)));

            var fr2 = await WithRetry.InvokeAsync(async() => await ac.FunctionAsync(1));

            await Assert.ThrowsExceptionAsync <ExceededMaxAttemptsException>(async() => { var fr = await WithRetry.InvokeAsync(() => ac.ExceptionAsync(1)); });

            WithRetry.SetDefaultPolicy(new RetryPolicy(100000, TimeSpan.FromMilliseconds(10)));

            await Assert.ThrowsExceptionAsync <ExceededMaxWaitTimeException>(async() => { var fr = await WithRetry.InvokeAsync(() => ac.ExceptionAsync(1)); });
        }
Esempio n. 2
0
        private Task Foo()
        {
            var ac = new WithRetryTestClass();

            try
            {
                var x = 1;
                var y = WithRetryTestClass.Invoke(() => { return(ac.FunctionAsync(x)); });
                WithRetryTestClass.Invoke(async() =>
                {
                    var b = await ac.FunctionAsync(x);
                    if (b == 2)
                    {
                        Console.Write("");
                    }
                });
                return(y);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(Task.FromException(ex));
            }
        }