10#ifndef NROS_RCLCPP_FUTURE_HPP
11#define NROS_RCLCPP_FUTURE_HPP
17#include "rclcpp/size_bound.hpp"
33template <
typename M>
class Subscription;
37template <
typename A>
class Client;
48template <
typename S>
class PollClient;
74 if (slot_ < 0 || !take_fn_)
return false;
75 if (ready_)
return true;
79 if (
ret == 0 && len > 0) {
81 cached_len_ = len <
sizeof(cached_buf_) ? len :
sizeof(cached_buf_);
82 for (
size_t i = 0;
i < cached_len_; ++
i)
83 cached_buf_[
i] =
buf[
i];
97 if (T::ffi_deserialize(cached_buf_, cached_len_, &
out) != 0) {
149 : client_storage_(
other.client_storage_), take_fn_(
other.take_fn_), slot_(
other.slot_),
150 ready_(
other.ready_), cached_len_(
other.cached_len_) {
151 for (
size_t i = 0;
i < cached_len_; ++
i)
152 cached_buf_[
i] =
other.cached_buf_[
i];
154 other.ready_ =
false;
158 if (
this != &
other) {
159 client_storage_ =
other.client_storage_;
160 take_fn_ =
other.take_fn_;
162 ready_ =
other.ready_;
163 cached_len_ =
other.cached_len_;
164 for (
size_t i = 0;
i < cached_len_; ++
i)
165 cached_buf_[
i] =
other.cached_buf_[
i];
167 other.ready_ =
false;
182 template <
typename S>
friend class ::rclcpp::PollClient;
183 template <
typename A>
friend class ::rclcpp_action::Client;
188 : client_storage_(storage), take_fn_(
fn), slot_(
slot), ready_(
false), cached_len_(0) {}
190 void* client_storage_;
Definition client.hpp:129
Future & operator=(Future &&other) noexcept
Definition future.hpp:157
Result wait(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition future.hpp:114
Future(Future &&other) noexcept
Definition future.hpp:148
Future()
Default constructor – creates an empty/consumed future.
Definition future.hpp:175
friend class ::rclcpp_action::Client
Definition future.hpp:183
~Future()
Definition future.hpp:172
bool is_consumed() const
Check if the future has been consumed or cancelled.
Definition future.hpp:145
void cancel()
Cancel the pending operation (idempotent).
Definition future.hpp:142
Result try_take(T &out)
Definition future.hpp:93
bool is_ready()
Check if the result has arrived (non-blocking).
Definition future.hpp:73
Definition result.hpp:216
static constexpr ResultOf success()
Named constructors.
Definition result.hpp:238
int nros_cpp_ret_t
Definition future.hpp:21
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
uint64_t nros_cpp_time_ns(void)
ResultOf< void > Result
Definition result.hpp:246
@ Error
Generic failure not covered by a more specific code.
@ Timeout
Operation deadline elapsed before completion.
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.