Skip to content

Reactive async #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reactive sequence deals with return status async actions
  • Loading branch information
miccol committed Apr 4, 2019
commit e71630748efec456c138dd484f430c5e35caa88b
58 changes: 40 additions & 18 deletions src/controls/reactive_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,53 @@ NodeStatus ReactiveSequence::tick()
for (size_t index = 0; index < childrenCount(); index++)
{
TreeNode* current_child_node = children_nodes_[index];
const NodeStatus child_status = current_child_node->executeTick();
NodeStatus child_status = NodeStatus::IDLE;

switch (child_status)
if (current_child_node->type() != NodeType::ACTION_ASYNC)
{
child_status = current_child_node->executeTick();
}
else
{
case NodeStatus::RUNNING:
if (current_child_node->status() != NodeStatus::RUNNING)
{
running_count++;
haltChildren(index+1);
return NodeStatus::RUNNING;
// if not running already, tick it
current_child_node->executeTick();
do
{
child_status = current_child_node->status();
} while (child_status == NodeStatus::IDLE);
}

case NodeStatus::FAILURE:
else
{
haltChildren(0);
return NodeStatus::FAILURE;
child_status = NodeStatus::RUNNING;
}
case NodeStatus::SUCCESS:
{
success_count++;
}break;
}

case NodeStatus::IDLE:
{
throw LogicError("A child node must never return IDLE");
}
switch (child_status)
{
case NodeStatus::RUNNING:
{
running_count++;
std::this_thread::sleep_for(milliseconds(3000));
haltChildren(index+1);
return NodeStatus::RUNNING;
}

case NodeStatus::FAILURE:
{
haltChildren(index+1);
return NodeStatus::FAILURE;
}
case NodeStatus::SUCCESS:
{
success_count++;
}break;

case NodeStatus::IDLE:
{
throw LogicError("A child node must never return IDLE");
}
} // end switch
} //end for

Expand Down