Skip to content

Commit e9b163f

Browse files
committed
spin_all with a zero timeout.
Signed-off-by: Tomoya Fujita <[email protected]>
1 parent d3c0049 commit e9b163f

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

rclcpp/include/rclcpp/executor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ class Executor
305305
* If the time that waitables take to be executed is longer than the period on which new waitables
306306
* become ready, this method will execute work repeatedly until `max_duration` has elapsed.
307307
*
308-
* \param[in] max_duration The maximum amount of time to spend executing work. Must be positive.
308+
* \param[in] max_duration The maximum amount of time to spend executing work, must be >= 0.
309+
* \throw throw std::invalid_argument if max_duration is less than 0.
309310
* Note that spin_all() may take longer than this time as it only returns once max_duration has
310311
* been exceeded.
311312
*/

rclcpp/include/rclcpp/executors/static_single_threaded_executor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ class StaticSingleThreadedExecutor : public rclcpp::Executor
9999

100100
/// Static executor implementation of spin all
101101
/**
102-
* This non-blocking function will execute entities until
103-
* timeout or no more work available. If new entities get ready
104-
* while executing work available, they will be executed
102+
* This non-blocking function will execute entities until timeout (must be >= 0)
103+
* or no more work available.
104+
* If new entities get ready while executing work available, they will be executed
105105
* as long as the timeout hasn't expired.
106106
*
107107
* Example:

rclcpp/src/rclcpp/executor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ void Executor::spin_some(std::chrono::nanoseconds max_duration)
414414

415415
void Executor::spin_all(std::chrono::nanoseconds max_duration)
416416
{
417-
if (max_duration <= 0ns) {
418-
throw std::invalid_argument("max_duration must be positive");
417+
if (max_duration < 0ns) {
418+
throw std::invalid_argument("max_duration must be greater than or equal to 0");
419419
}
420420
return this->spin_some_impl(max_duration, true);
421421
}

rclcpp/src/rclcpp/executors/static_single_threaded_executor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ StaticSingleThreadedExecutor::spin_some(std::chrono::nanoseconds max_duration)
7171
void
7272
StaticSingleThreadedExecutor::spin_all(std::chrono::nanoseconds max_duration)
7373
{
74-
if (max_duration <= std::chrono::nanoseconds(0)) {
75-
throw std::invalid_argument("max_duration must be positive");
74+
if (max_duration < std::chrono::nanoseconds(0)) {
75+
throw std::invalid_argument("max_duration must be greater than or equal to 0");
7676
}
7777
return this->spin_some_impl(max_duration, true);
7878
}

rclcpp/test/rclcpp/test_executor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ TEST_F(TestExecutor, spin_all_invalid_duration) {
248248

249249
RCLCPP_EXPECT_THROW_EQ(
250250
dummy.spin_all(std::chrono::nanoseconds(-1)),
251-
std::invalid_argument("max_duration must be positive"));
251+
std::invalid_argument("max_duration must be greater than or equal to 0"));
252252
}
253253

254254
TEST_F(TestExecutor, spin_some_in_spin_some) {

0 commit comments

Comments
 (0)