Exemple #1
0
        /// <summary>
        /// Retry a task composition using the specified retry policy
        /// </summary>
        /// <typeparam name="T">The composer payload type</typeparam>
        /// <param name="composer">The task composer</param>
        /// <param name="retryPolicy">The retry policy</param>
        /// <param name="callback">The task composition callback</param>
        /// <returns>The original task composer</returns>
        public static Composer <T> Retry <T>(this Composer <T> composer, IRetryPolicy retryPolicy, Action <Composer <T> > callback)
        {
            IRetryContext retryContext = null;

            composer.ComposeTask(taskComposer =>
            {
                retryContext = retryPolicy.GetRetryContext();

                Attempt(taskComposer, retryContext, callback);
            });

            composer.Finally((_, status) =>
            {
                if (retryContext != null)
                {
                    retryContext.Complete(status);
                }
            });

            return(composer);
        }