Merge pull request #25 from ros2/spin-node-until-future-complete
Added spin_node_until_future_complete
This commit is contained in:
commit
8ad1f1f4c5
2 changed files with 30 additions and 0 deletions
|
@ -15,8 +15,11 @@
|
||||||
#ifndef RCLCPP_RCLCPP_EXECUTORS_HPP_
|
#ifndef RCLCPP_RCLCPP_EXECUTORS_HPP_
|
||||||
#define RCLCPP_RCLCPP_EXECUTORS_HPP_
|
#define RCLCPP_RCLCPP_EXECUTORS_HPP_
|
||||||
|
|
||||||
|
#include <future>
|
||||||
#include <rclcpp/executors/multi_threaded_executor.hpp>
|
#include <rclcpp/executors/multi_threaded_executor.hpp>
|
||||||
#include <rclcpp/executors/single_threaded_executor.hpp>
|
#include <rclcpp/executors/single_threaded_executor.hpp>
|
||||||
|
#include <rclcpp/node.hpp>
|
||||||
|
#include <rclcpp/utilities.hpp>
|
||||||
|
|
||||||
namespace rclcpp
|
namespace rclcpp
|
||||||
{
|
{
|
||||||
|
@ -26,6 +29,22 @@ namespace executors
|
||||||
using rclcpp::executors::multi_threaded_executor::MultiThreadedExecutor;
|
using rclcpp::executors::multi_threaded_executor::MultiThreadedExecutor;
|
||||||
using rclcpp::executors::single_threaded_executor::SingleThreadedExecutor;
|
using rclcpp::executors::single_threaded_executor::SingleThreadedExecutor;
|
||||||
|
|
||||||
|
template<typename FutureT>
|
||||||
|
std::shared_future<FutureT> &
|
||||||
|
spin_node_until_future_complete(
|
||||||
|
rclcpp::executor::Executor & executor, rclcpp::node::Node::SharedPtr & node_ptr,
|
||||||
|
std::shared_future<FutureT> & future)
|
||||||
|
{
|
||||||
|
std::future_status status;
|
||||||
|
// TODO: does not work recursively right, can't call spin_node_until_future_complete
|
||||||
|
// inside a callback executed by an executor.
|
||||||
|
do {
|
||||||
|
executor.spin_node_some(node_ptr);
|
||||||
|
status = future.wait_for(std::chrono::seconds(0));
|
||||||
|
} while (status != std::future_status::ready && rclcpp::utilities::ok());
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace executors
|
} // namespace executors
|
||||||
} // namespace rclcpp
|
} // namespace rclcpp
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,17 @@ void spin(Node::SharedPtr & node_ptr)
|
||||||
executor.spin();
|
executor.spin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FutureT>
|
||||||
|
std::shared_future<FutureT> &
|
||||||
|
spin_until_future_complete(
|
||||||
|
Node::SharedPtr & node_ptr, std::shared_future<FutureT> & future)
|
||||||
|
{
|
||||||
|
rclcpp::executors::SingleThreadedExecutor executor;
|
||||||
|
rclcpp::executors::spin_node_until_future_complete<FutureT>(
|
||||||
|
executor, node_ptr, future);
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace rclcpp */
|
} /* namespace rclcpp */
|
||||||
|
|
||||||
#endif /* RCLCPP_RCLCPP_RCLCPP_HPP_ */
|
#endif /* RCLCPP_RCLCPP_RCLCPP_HPP_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue