Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e22b120

Browse files
committed
reactive fallback deals with return status async actions
1 parent 91994f8 commit e22b120

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

src/controls/reactive_fallback.cpp

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,54 @@ NodeStatus ReactiveFallback::tick()
2222
for (size_t index = 0; index < childrenCount(); index++)
2323
{
2424
TreeNode* current_child_node = children_nodes_[index];
25-
const NodeStatus child_status = current_child_node->executeTick();
25+
NodeStatus child_status = NodeStatus::IDLE;
2626

27-
switch (child_status)
27+
if (current_child_node->type() != NodeType::ACTION_ASYNC)
28+
{
29+
child_status = current_child_node->executeTick();
30+
}
31+
else
2832
{
29-
case NodeStatus::RUNNING:
33+
if (current_child_node->status() != NodeStatus::RUNNING)
3034
{
31-
haltChildren(index+1);
32-
return NodeStatus::RUNNING;
33-
}
35+
// if not running already, tick it
36+
current_child_node->executeTick();
37+
do
38+
{
3439

35-
case NodeStatus::FAILURE:
36-
{
37-
failure_count++;
38-
}break;
40+
child_status = current_child_node->status();
3941

40-
case NodeStatus::SUCCESS:
41-
{
42-
haltChildren(0);
43-
return NodeStatus::SUCCESS;
42+
} while (child_status == NodeStatus::IDLE);
4443
}
45-
46-
case NodeStatus::IDLE:
44+
else
4745
{
48-
throw LogicError("A child node must never return IDLE");
46+
child_status = NodeStatus::RUNNING;
4947
}
48+
}
49+
50+
switch (child_status)
51+
{
52+
case NodeStatus::RUNNING:
53+
{
54+
haltChildren(index+1);
55+
return NodeStatus::RUNNING;
56+
}break;
57+
58+
case NodeStatus::FAILURE:
59+
{
60+
failure_count++;
61+
}break;
62+
63+
case NodeStatus::SUCCESS:
64+
{
65+
haltChildren(index+1);
66+
return NodeStatus::SUCCESS;
67+
}break;
68+
69+
case NodeStatus::IDLE:
70+
{
71+
throw LogicError("A child node must never return IDLE");
72+
}
5073
} // end switch
5174
} //end for
5275

0 commit comments

Comments
 (0)