示例#1
0
        private static void SleepBackOffMultiplier(int i)
        {
            //exponential/random retry back-off.
            var rand    = new Random(Guid.NewGuid().GetHashCode());
            var nextTry = rand.Next(
                (int)Math.Pow(i, 2), (int)Math.Pow(i + 1, 2) + 1);

            TaskUtils.Sleep(nextTry);
        }
示例#2
0
        public static void WaitWhile(Func <bool> condition, int millisecondTimeout, int millsecondPollPeriod = 10)
        {
            var timer = System.Diagnostics.Stopwatch.StartNew();

            while (condition())
            {
                TaskUtils.Sleep(millsecondPollPeriod);

                if (timer.ElapsedMilliseconds > millisecondTimeout)
                {
                    throw new TimeoutException("Timed out waiting for condition function.");
                }
            }
        }
示例#3
0
 /// <summary>
 /// How long to sleep before next retry using Exponential BackOff delay with Full Jitter.
 /// </summary>
 /// <param name="retriesAttempted"></param>
 public static void SleepBackOffMultiplier(int retriesAttempted) => TaskUtils.Sleep(CalculateFullJitterBackOffDelay(retriesAttempted));