Exemplo n.º 1
0
        public static async Task UntilCancelled(CancellationToken cancellationToken, Func <Task> callback)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            await Task.Yield();

            IRepeatPolicy repeatPolicy = UntilCancelled(cancellationToken);

            using (IRepeatContext repeatContext = repeatPolicy.GetRepeatContext())
            {
                TimeSpan delay = TimeSpan.Zero;
                do
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    if (delay > TimeSpan.Zero)
                    {
                        await Task.Delay(delay, repeatContext.CancellationToken).ConfigureAwait(false);
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    await callback().ConfigureAwait(false);
                }while (repeatContext.CanRepeat(out delay));
            }
        }
Exemplo n.º 2
0
        static async Task Attempt(IRepeatContext repeatContext, T context, IPipe <T> next)
        {
            TimeSpan delay = TimeSpan.Zero;

            do
            {
                if (delay > TimeSpan.Zero)
                {
                    await Task.Delay(delay, repeatContext.CancellationToken);
                }

                await next.Send(context);
            }while (repeatContext.CanRepeat(out delay));
        }
Exemplo n.º 3
0
        public static async Task UntilCancelled(CancellationToken cancellationToken, Func <Task> callback)
        {
            IRepeatPolicy repeatPolicy = UntilCancelled(cancellationToken);

            using (IRepeatContext repeatContext = repeatPolicy.GetRepeatContext())
            {
                TimeSpan delay = TimeSpan.Zero;
                do
                {
                    if (delay > TimeSpan.Zero)
                    {
                        await Task.Delay(delay, repeatContext.CancellationToken);
                    }

                    await callback();
                }while (repeatContext.CanRepeat(out delay));
            }
        }