Skip to content

Commit 7804051

Browse files
Janosch MachowinskiJanosch Machowinski
authored andcommitted
feat: Changed interface of spin_until_future_complete_impl
This change allows it to use a second thread to wait for the future to become ready. Signed-off-by: Janosch Machowinski <[email protected]>
1 parent 3b8c558 commit 7804051

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

rclcpp/include/rclcpp/executor.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ class Executor
355355
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
356356
{
357357
return spin_until_future_complete_impl(std::chrono::duration_cast<std::chrono::nanoseconds>(
358-
timeout), [&future] () {
359-
return future.wait_for(std::chrono::seconds(0));
358+
timeout), [&future] (std::chrono::nanoseconds wait_time) {
359+
return future.wait_for(wait_time);
360360
}
361361
);
362362
}
@@ -406,17 +406,17 @@ class Executor
406406
/// Spin (blocking) until the get_future_status returns ready, max_duration is reached,
407407
/// or rclcpp is interrupted.
408408
/**
409-
* \param[in] get_future_status A function returning the status of a future that is been waited for.
410409
* \param[in] max_duration Optional duration parameter, which gets passed to Executor::spin_node_once.
411410
* `-1` is block forever, `0` is non-blocking.
412411
* If the time spent inside the blocking loop exceeds this timeout, return a TIMEOUT return
413412
* code.
413+
* \param[in] wait_for_future A function waiting for a future to become ready.
414414
* \return The return code, one of `SUCCESS`, `INTERRUPTED`, or `TIMEOUT`.
415415
*/
416416
RCLCPP_PUBLIC
417417
virtual FutureReturnCode spin_until_future_complete_impl(
418418
std::chrono::nanoseconds max_duration,
419-
const std::function<std::future_status ()> & get_future_status);
419+
const std::function<std::future_status (std::chrono::nanoseconds wait_time)> & wait_for_future);
420420

421421
/// Collect work and execute available work, optionally within a duration.
422422
/**

rclcpp/src/rclcpp/executor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ Executor::spin_node_once_nanoseconds(
272272

273273
rclcpp::FutureReturnCode Executor::spin_until_future_complete_impl(
274274
std::chrono::nanoseconds timeout,
275-
const std::function<std::future_status ()> & get_future_status)
275+
const std::function<std::future_status (std::chrono::nanoseconds wait_time)> & get_future_status)
276276
{
277277
// TODO(wjwwood): does not work recursively; can't call spin_node_until_future_complete
278278
// inside a callback executed by an executor.
279279

280280
// Check the future before entering the while loop.
281281
// If the future is already complete, don't try to spin.
282-
std::future_status status = get_future_status();
282+
std::future_status status = get_future_status(std::chrono::seconds(0));
283283
if (status == std::future_status::ready) {
284284
return FutureReturnCode::SUCCESS;
285285
}
@@ -301,7 +301,7 @@ rclcpp::FutureReturnCode Executor::spin_until_future_complete_impl(
301301
spin_once_impl(timeout_left);
302302

303303
// Check if the future is set, return SUCCESS if it is.
304-
status = get_future_status();
304+
status = get_future_status(std::chrono::seconds(0));
305305
if (status == std::future_status::ready) {
306306
return FutureReturnCode::SUCCESS;
307307
}

0 commit comments

Comments
 (0)