public SequenceItemHar(RunState state, SequenceItem sequenceItem, object model, IEnumerable <SequenceItem> nextSequenceItems)
     : base(state, sequenceItem, model, nextSequenceItems)
 {
 }
        public async Task <SequenceItemDispatcherResult> SequenceItemRetryDispatcherAsync(CancellationToken cancelToken, bool isInstantRetry, IEnumerable <ISequenceItemAction> toRetry, RunState state, Stack <ISequenceItemAction> retryAfterList, Stack <KeyValuePair <string, ISequenceItemAction> > breadcrumbs)
        {
            var allResults = new List <SequenceItemDispatcherResult>();

            foreach (var sequenceItemAction in toRetry)
            {
                try
                {
                    if (sequenceItemAction == null)
                    {
                        throw new InvalidOperationException();
                    }


                    var retriesLeft = isInstantRetry
                        ? (sequenceItemAction.GetSequenceItem().max_instant_retrys ?? 0) - (sequenceItemAction.ActionExecuteCount - 1)
                        : (sequenceItemAction.GetSequenceItem().max_instant_retrys ?? 0 + sequenceItemAction.GetSequenceItem().max_delayed_retrys ?? 0) - (sequenceItemAction.ActionExecuteCount - 1);

                    if (retriesLeft <= 0)
                    {
                        sequenceItemAction.Fail();
                        allResults.Add(new SequenceItemDispatcherResult {
                            IsSuccess = false, Model = null
                        });                                                                                  //, SequenceItemAction = new[] { sequenceItemAction } });
                        continue;
                    }

                    var policy = Policy.Handle <Exception>().Retry(retriesLeft);

                    breadcrumbs.Push(new KeyValuePair <string, ISequenceItemAction>(sequenceItemAction.GetSequenceItem().breadcrumb, sequenceItemAction));

                    var result = await policy.Execute(async() => await sequenceItemAction.ActionAsync(cancelToken));

                    allResults.Add(new SequenceItemDispatcherResult {
                        IsSuccess = !sequenceItemAction.IsFail, Model = result
                    });                                                                                                         //, SequenceItemAction = new[] { sequenceItemAction } });
                }
                catch (Exception e)
                {
                    if (!CanDealWithException(e, isInstantRetry, sequenceItemAction, sequenceItemAction?.GetSequenceItem(), /*retryAfterList, */ breadcrumbs))
                    {
                        sequenceItemAction?.Fail(e);
                    }
                }
            }