Пример #1
0
        /// <summary>
        ///     Creates a new Composer, which can be used to compose a task chain, which can be added to an
        ///     existing composer as a single task. Note that this executes on the task chain, and not immediately.
        /// </summary>
        /// <typeparam name="T">The payload type</typeparam>
        /// <param name="composer">The existing composer</param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static Composer <T> ComposeTask <T>(this Composer <T> composer, Action <Composer> callback)
        {
            composer.ExecuteAsync(async(payload, cancellationToken) =>
            {
                await ComposerFactory.Compose(callback, composer.CancellationToken);

                return(composer.Payload);
            });

            return(composer);
        }
Пример #2
0
        /// <summary>
        ///     Creates a new Composer, which can be used to compose a task chain, which can be added to an
        ///     existing composer as a single task. Note that this executes on the task chain, and not immediately.
        /// </summary>
        /// <typeparam name="T">The payload type</typeparam>
        /// <typeparam name="TPayload">The child payload type</typeparam>
        /// <param name="composer">The existing composer</param>
        /// <param name="payload">The child payload</param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static Composer <T> ComposeTask <T, TPayload>(this Composer <T> composer, Func <T, TPayload> payload,
                                                             Action <Composer <TPayload> > callback)
        {
            composer.ExecuteAsync(async(p, cancellationToken) =>
            {
                TPayload taskPayload = payload(p);

                await ComposerFactory.Compose(taskPayload, callback, composer.CancellationToken);

                return(composer.Payload);
            });

            return(composer);
        }
Пример #3
0
        static void Attempt(Composer composer, TimeSpan interval, Action <Composer> callback, CancellationToken repeatCancellationToken)
        {
            composer.ComposeTask(callback);

            composer.ExecuteAsync(token =>
            {
                if (repeatCancellationToken.IsCancellationRequested)
                {
                    return(TaskUtil.Completed());
                }

                return(ComposerFactory.Compose(x =>
                {
                    x.Delay(interval);

                    Attempt(x, interval, callback, repeatCancellationToken);
                }, token));
            }, ExecuteOptions.RunSynchronously);
        }
Пример #4
0
        /// <summary>
        ///     Creates a new Composer, which can be used to compose a task chain, which can be added to an
        ///     existing composer as a single task. Note that this executes on the task chain, and not immediately.
        /// </summary>
        /// <param name="composer">The existing composer</param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static Composer ComposeTask(this Composer composer, Action <Composer> callback)
        {
            composer.ExecuteAsync(cancellationToken => ComposerFactory.Compose(callback, composer.CancellationToken));

            return(composer);
        }
Пример #5
0
        /// <summary>
        ///     Creates a new Composer, which can be used to compose a task chain, which can be added to an
        ///     existing composer as a single task. Note that this executes on the task chain, and not immediately.
        /// </summary>
        /// <typeparam name="T">The payload type</typeparam>
        /// <param name="composer">The existing composer</param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static Composer <T> ComposeTask <T>(this Composer <T> composer, Action <Composer <T> > callback)
        {
            composer.ExecuteAsync((payload, cancellationToken) => ComposerFactory.Compose(payload, callback, composer.CancellationToken));

            return(composer);
        }
Пример #6
0
        static async Task <T> ComposeCompensationTask <T>(T payload, Action <Composer> callback, CancellationToken cancellationToken)
        {
            await ComposerFactory.Compose(callback, cancellationToken);

            return(payload);
        }
Пример #7
0
 /// <summary>
 ///     Creates a new Composer, which can be used to compose a task chain, which can be added to an
 ///     existing composer as a single task. Note that this executes on the task chain, and not immediately.
 /// </summary>
 /// <param name="compensation"></param>
 /// <param name="callback"></param>
 /// <returns></returns>
 public static CompensationResult <T> ComposeTask <T>(this Compensation <T> compensation, Action <Composer <T> > callback)
 {
     return(compensation.Task(ComposerFactory.Compose(compensation.Payload, callback, compensation.CancellationToken)));
 }
Пример #8
0
 /// <summary>
 ///     Creates a new Composer, which can be used to compose a task chain, which can be added to an
 ///     existing composer as a single task. Note that this executes on the task chain, and not immediately.
 /// </summary>
 /// <param name="compensation"></param>
 /// <param name="callback"></param>
 /// <returns></returns>
 public static CompensationResult ComposeTask(this Compensation compensation, Action <Composer> callback)
 {
     return(compensation.Task(ComposerFactory.Compose(callback, compensation.CancellationToken)));
 }