Skip to content

Commit 05625f0

Browse files
committed
Add exhaustive option to spin_some
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
1 parent 0f38c51 commit 05625f0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

rclcpp/include/rclcpp/executor.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,16 @@ class Executor
169169
* \param[in] max_duration The maximum amount of time to spend executing work, or 0 for no limit.
170170
* Note that spin_some() may take longer than this time as it only returns once max_duration has
171171
* been exceeded.
172+
* \param[in] exhaustive When true, it will try to collect entities again after executing executables
173+
* until there is no more ready entities or the specified duration has been reached.
174+
* When there are subscriptions/clients with long history queues, this will ensure all messages/requestes
175+
* available are handled.
172176
*/
173177
RCLCPP_PUBLIC
174178
virtual void
175-
spin_some(std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0));
179+
spin_some(
180+
std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0),
181+
bool exhaustive = false);
176182

177183
RCLCPP_PUBLIC
178184
virtual void

rclcpp/src/rclcpp/executor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Executor::spin_node_some(std::shared_ptr<rclcpp::Node> node)
213213
}
214214

215215
void
216-
Executor::spin_some(std::chrono::nanoseconds max_duration)
216+
Executor::spin_some(std::chrono::nanoseconds max_duration, bool exhaustive)
217217
{
218218
auto start = std::chrono::steady_clock::now();
219219
auto max_duration_not_elapsed = [max_duration, start]() {
@@ -242,7 +242,7 @@ Executor::spin_some(std::chrono::nanoseconds max_duration)
242242
execute_any_executable(any_exec);
243243
work_available = true;
244244
} else {
245-
if (!work_available) {
245+
if (!work_available || !exhaustive) {
246246
break;
247247
}
248248
work_available = false;

0 commit comments

Comments
 (0)