private async Task CommitCurrentTreeNode()

in Forge.TreeWalker/src/TreeWalkerSession.cs [1121:1153]


        private async Task CommitCurrentTreeNode(string treeNodeKey, TreeNode treeNode)
        {
            List<KeyValuePair<string, object>> itemsToPersist = new List<KeyValuePair<string, object>>();

            // Handle revisit/cycle case if this node has been previously completed and we are rehydrated or the override flag is set.
            if (treeNode.Actions != null && (this.hasSessionRehydrated || this.Parameters.RetryCurrentTreeNodeActions))
            {
                // Check if all actions already have an action response.
                foreach (KeyValuePair<string, TreeAction> kvp in treeNode.Actions)
                {
                    string treeActionKey = kvp.Key;
                    ActionResponse actionResponse = await this.GetOutputAsync(treeActionKey).ConfigureAwait(false);

                    if (actionResponse == null)
                    {
                        // If this session has rehydrated and actionResponse is null, then this must be the first time visiting this TreeNode.
                        itemsToPersist.Clear();
                        break;
                    }

                    // If this session has rehydrated and actionResponses exist, then this TreeNode was previously visited.
                    // Clear the ActionResponse and Intermediates, and persist PreviousActionResponse.
                    itemsToPersist.Add(new KeyValuePair<string, object>(treeActionKey + ActionResponseSuffix, null));
                    itemsToPersist.Add(new KeyValuePair<string, object>(treeActionKey + IntermediatesSuffix, null));
                    itemsToPersist.Add(new KeyValuePair<string, object>(treeActionKey + PreviousActionResponseSuffix, actionResponse));
                }
            }

            itemsToPersist.Add(new KeyValuePair<string, object>(CurrentTreeNodeSuffix, treeNodeKey));

            await this.Parameters.ForgeState.SetRange(itemsToPersist);
            this.hasSessionRehydrated = true;
        }