diff --git a/rclcpp/include/rclcpp/executor.hpp b/rclcpp/include/rclcpp/executor.hpp index 39acba3ec4..a5e21fa747 100644 --- a/rclcpp/include/rclcpp/executor.hpp +++ b/rclcpp/include/rclcpp/executor.hpp @@ -169,10 +169,16 @@ class Executor * \param[in] max_duration The maximum amount of time to spend executing work, or 0 for no limit. * Note that spin_some() may take longer than this time as it only returns once max_duration has * been exceeded. + * \param[in] exhaustive When true, it will try to collect entities again after executing executables + * until there is no more ready entities or the specified duration has been reached. + * When there are subscriptions/clients with long history queues, this will ensure all messages/requestes + * available are handled. */ RCLCPP_PUBLIC virtual void - spin_some(std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0)); + spin_some( + std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0), + bool exhaustive = false); RCLCPP_PUBLIC virtual void diff --git a/rclcpp/src/rclcpp/executor.cpp b/rclcpp/src/rclcpp/executor.cpp index 94f29387a0..8c5d3acb7f 100644 --- a/rclcpp/src/rclcpp/executor.cpp +++ b/rclcpp/src/rclcpp/executor.cpp @@ -213,7 +213,7 @@ Executor::spin_node_some(std::shared_ptr node) } void -Executor::spin_some(std::chrono::nanoseconds max_duration) +Executor::spin_some(std::chrono::nanoseconds max_duration, bool exhaustive) { auto start = std::chrono::steady_clock::now(); auto max_duration_not_elapsed = [max_duration, start]() { @@ -242,7 +242,7 @@ Executor::spin_some(std::chrono::nanoseconds max_duration) execute_any_executable(any_exec); work_available = true; } else { - if (!work_available) { + if (!work_available || !exhaustive) { break; } work_available = false;