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

Skip to content

Commit e716307

Browse files
committed
reactive sequence deals with return status async actions
1 parent e22b120 commit e716307

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

src/controls/reactive_sequence.cpp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,53 @@ NodeStatus ReactiveSequence::tick()
2323
for (size_t index = 0; index < childrenCount(); index++)
2424
{
2525
TreeNode* current_child_node = children_nodes_[index];
26-
const NodeStatus child_status = current_child_node->executeTick();
26+
NodeStatus child_status = NodeStatus::IDLE;
2727

28-
switch (child_status)
28+
if (current_child_node->type() != NodeType::ACTION_ASYNC)
29+
{
30+
child_status = current_child_node->executeTick();
31+
}
32+
else
2933
{
30-
case NodeStatus::RUNNING:
34+
if (current_child_node->status() != NodeStatus::RUNNING)
3135
{
32-
running_count++;
33-
haltChildren(index+1);
34-
return NodeStatus::RUNNING;
36+
// if not running already, tick it
37+
current_child_node->executeTick();
38+
do
39+
{
40+
child_status = current_child_node->status();
41+
} while (child_status == NodeStatus::IDLE);
3542
}
36-
37-
case NodeStatus::FAILURE:
43+
else
3844
{
39-
haltChildren(0);
40-
return NodeStatus::FAILURE;
45+
child_status = NodeStatus::RUNNING;
4146
}
42-
case NodeStatus::SUCCESS:
43-
{
44-
success_count++;
45-
}break;
47+
}
4648

47-
case NodeStatus::IDLE:
48-
{
49-
throw LogicError("A child node must never return IDLE");
50-
}
49+
switch (child_status)
50+
{
51+
case NodeStatus::RUNNING:
52+
{
53+
running_count++;
54+
std::this_thread::sleep_for(milliseconds(3000));
55+
haltChildren(index+1);
56+
return NodeStatus::RUNNING;
57+
}
58+
59+
case NodeStatus::FAILURE:
60+
{
61+
haltChildren(index+1);
62+
return NodeStatus::FAILURE;
63+
}
64+
case NodeStatus::SUCCESS:
65+
{
66+
success_count++;
67+
}break;
68+
69+
case NodeStatus::IDLE:
70+
{
71+
throw LogicError("A child node must never return IDLE");
72+
}
5173
} // end switch
5274
} //end for
5375

0 commit comments

Comments
 (0)