10#ifndef NROS_CPP_FUTURE_HPP
11#define NROS_CPP_FUTURE_HPP
44 if (slot_ < 0 || !try_recv_fn_)
return false;
45 if (ready_)
return true;
49 if (
ret == 0 && len > 0) {
51 cached_len_ = len <
sizeof(cached_buf_) ? len :
sizeof(cached_buf_);
52 for (
size_t i = 0;
i < cached_len_; ++
i)
53 cached_buf_[
i] =
buf[
i];
67 if (T::ffi_deserialize(cached_buf_, cached_len_, &
out) != 0) {
119 : client_storage_(
other.client_storage_), try_recv_fn_(
other.try_recv_fn_),
120 slot_(
other.slot_), ready_(
other.ready_), cached_len_(
other.cached_len_) {
121 for (
size_t i = 0;
i < cached_len_; ++
i)
122 cached_buf_[
i] =
other.cached_buf_[
i];
124 other.ready_ =
false;
128 if (
this != &
other) {
129 client_storage_ =
other.client_storage_;
130 try_recv_fn_ =
other.try_recv_fn_;
132 ready_ =
other.ready_;
133 cached_len_ =
other.cached_len_;
134 for (
size_t i = 0;
i < cached_len_; ++
i)
135 cached_buf_[
i] =
other.cached_buf_[
i];
137 other.ready_ =
false;
153 template <
typename S>
friend class Client;
159 : client_storage_(storage), try_recv_fn_(
fn), slot_(
slot), ready_(
false), cached_len_(0) {}
161 void* client_storage_;
162 TryRecvFn try_recv_fn_;
166 uint8_t cached_buf_[T::SERIALIZED_SIZE_MAX];
Definition action_client.hpp:67
Future & operator=(Future &&other) noexcept
Definition future.hpp:127
Result try_take(T &out)
Definition future.hpp:63
void cancel()
Cancel the pending operation (idempotent).
Definition future.hpp:112
bool is_ready()
Check if the result has arrived (non-blocking).
Definition future.hpp:43
Result wait(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition future.hpp:84
bool is_consumed() const
Check if the future has been consumed or cancelled.
Definition future.hpp:115
Future(Future &&other) noexcept
Definition future.hpp:118
~Future()
Definition future.hpp:142
Future()
Default constructor – creates an empty/consumed future.
Definition future.hpp:145
static constexpr Result success()
Named constructors.
Definition result.hpp:74
int nros_cpp_ret_t
Definition future.hpp:20
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
uint64_t nros_cpp_time_ns(void)
@ 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.
nros::Result, nros::ErrorCode, and the NROS_TRY macro.