Пример #1
0
        /// <summary>
        /// Retry a task composition using the specified retry policy
        /// </summary>
        /// <param name="composer">The task composer</param>
        /// <param name="interval">The interval between each repetition</param>
        /// <param name="callback">The task composition callback</param>
        /// <param name="repeatCancellationToken">A cancellation token for the repeat-portion of the task composer</param>
        /// <returns>The original task composer</returns>
        public static Composer Repeat(this Composer composer, TimeSpan interval, Action<Composer> callback,
            CancellationToken repeatCancellationToken = default(CancellationToken))
        {
            if (interval < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("interval",
                    "The interval must be non-negative, and it must be less than or equal to Int32.MaxValue.");
            }

            composer.ComposeTask(taskComposer => Attempt(taskComposer, interval, callback, repeatCancellationToken));

            return composer;
        }
Пример #2
0
        /// <summary>
        /// Retry a task composition using the specified retry policy
        /// </summary>
        /// <param name="composer">The task composer</param>
        /// <param name="millisecondsInterval"></param>
        /// <param name="callback">The task composition callback</param>
        /// <param name="repeatCancellationToken"></param>
        /// <returns>The original task composer</returns>
        public static Composer Repeat(this Composer composer, int millisecondsInterval, Action<Composer> callback,
            CancellationToken repeatCancellationToken)
        {
            if (millisecondsInterval < 0)
            {
                throw new ArgumentOutOfRangeException("millisecondsInterval",
                    "The interval must be non-negative, and it must be less than or equal to Int32.MaxValue.");
            }

            composer.ComposeTask(
                taskComposer => Attempt(taskComposer, TimeSpan.FromMilliseconds(millisecondsInterval), callback, repeatCancellationToken));

            return composer;
        }