-
Notifications
You must be signed in to change notification settings - Fork 422
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
Added spin_node_until_future_complete #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,11 @@ | |
#ifndef RCLCPP_RCLCPP_EXECUTORS_HPP_ | ||
#define RCLCPP_RCLCPP_EXECUTORS_HPP_ | ||
|
||
#include <future> | ||
#include <rclcpp/executors/multi_threaded_executor.hpp> | ||
#include <rclcpp/executors/single_threaded_executor.hpp> | ||
#include <rclcpp/node.hpp> | ||
#include <rclcpp/utilities.hpp> | ||
|
||
namespace rclcpp | ||
{ | ||
|
@@ -26,6 +29,22 @@ namespace executors | |
using rclcpp::executors::multi_threaded_executor::MultiThreadedExecutor; | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need to return the passed in future? What would be a use case for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't need to, but it's convenient because one can write code like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For method chaining I find it pretty _un_intuitive that the function returns the future. Especially since it looks like that passing a temporary future does not work. I don't know if others have an opinion on this. We could always defer this to an API review in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function already returns the future, what changes do you suggest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not returning anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You meant intuitive or counter intuitive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is fine as is, the method chaining looks useful and I don't see that it needs to return anything else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, important spelling error: I meant unintuitive. The calling code has the future and it looks arbitrary and _un_intuitive to me why the method would return that specific argument for chaining. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Supporting chaining operators make usage much more compact. The other option I see is to have an additional or overridden |
||
} | ||
|
||
} // namespace executors | ||
} // namespace rclcpp | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worth putting a TODO here mentioning that this won't work recursively right now, i.e. you can't call
spin_node_until_future_complete
inside a callback executed by an executor.