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); }
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."); } } }
/// <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));