示例#1
0
        /// <summary>
        /// Runs the given closure at least once, or retries as many times specified, sleeping for the given timespan between executions.
        /// </summary>
        /// <param name="closure">The closure to run.</param>
        /// <param name="betweenRetriesSpan">A TimeSpan of time to sleep between executions (if needed to retry).</param>
        /// <param name="retries">Times to retry the closure before allowing the exception to bubble up, if any.</param>
        /// <param name="retryCondition">Optional condition to check before an execution retry is performed.</param>
        public static void Run(Action closure, TimeSpan betweenRetriesSpan, int retries = 3, Func <bool?> retryCondition = null)
        {
            var betweenRetriesDelegate = new BetweenRetriesDelegate(x => Thread.Sleep(betweenRetriesSpan));

            RetryRunner.Run(closure, retries, retryCondition, betweenRetriesDelegate);
        }
示例#2
0
        /// <summary>
        /// Runs the given closure at least once, or retries as many times specified, sleeping for the given timespan between executions.
        /// </summary>
        /// <typeparam name="T">The type of the closure´s output.</typeparam>
        /// <param name="closure">The closure to run.</param>
        /// <param name="betweenRetriesSpan">A TimeSpan of time to sleep between executions (if needed to retry).</param>
        /// <param name="retriesAfterException">Times to retry the closure before allowing the exception to bubble up, if any.</param>
        /// <param name="retryConditionWhenNoException">Optional condition to check before an execution retry is performed.</param>
        /// <returns>The output of the specified closure.</returns>
        public static T Run <T>(Func <T> closure, TimeSpan betweenRetriesSpan, int retriesAfterException = 3, Func <bool?> retryConditionWhenNoException = null)
        {
            var betweenRetriesDelegate = new BetweenRetriesDelegate(x => Thread.Sleep(betweenRetriesSpan));

            return(RetryRunner.Run(closure, retriesAfterException, retryConditionWhenNoException, betweenRetriesDelegate));
        }