internal void RegisterPromise(BasePromiseInfo promise, int insertionIndex = -1)
        {
            //If we are currently in a execution, all the promises need to be on the top
            if (InPromiseExecution)
            {
                Promises.Insert(PromisesInsertionIndex++, promise);
            }
            else if (insertionIndex != -1)
            {
                Promises.Insert(insertionIndex, promise);
            }
            else
            {
                var index         = -1;
                var lastDelimiter = Promises.Where((p) => p is IDelimiterPromise).FirstOrDefault();
                if (lastDelimiter != null)
                {
                    index = Promises.IndexOf(lastDelimiter);
                }
                if (index != -1)
                {
                    Promises.Insert(index, promise);
                }
                else
                {
                    Promises.Add(promise);
                }
            }

            // Promise must be stored in the cache to create a valid reference for its surrogate
            StateManager.Current.AddNewObject(promise);

            LastPromise = promise;
            StateManager.Current.Tracker.MarkAsModified(this, "Promises");
        }