nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
nros::Future< T > Class Template Reference

#include <future.hpp>

Public Member Functions

void cancel ()
 Cancel the pending operation (idempotent).
 
 Future ()
 Default constructor – creates an empty/consumed future.
 
 Future (Future &&other) noexcept
 
bool is_consumed () const
 Check if the future has been consumed or cancelled.
 
bool is_ready ()
 Check if the result has arrived (non-blocking).
 
Futureoperator= (Future &&other) noexcept
 
Result try_take (T &out)
 
Result wait (void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
 
 ~Future ()
 

Friends

template<typename A >
class ActionClient
 
template<typename S >
class Client
 

Detailed Description

template<typename T>
class nros::Future< T >

Single-shot deferred result for request/response operations.

Returned by Client<S>::send_request. The future is consumed when the result is taken – move-only, single-shot.

Usage:

auto fut = client.send_request(req);
ResponseType resp;
NROS_TRY(fut.wait(executor.handle(), 5000, resp));
Definition future.hpp:40
Result wait(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition future.hpp:84
Future()
Default constructor – creates an empty/consumed future.
Definition future.hpp:145
#define NROS_TRY(expr)
Definition result.hpp:90

Constructor & Destructor Documentation

◆ Future() [1/2]

template<typename T >
nros::Future< T >::Future ( Future< T > &&  other)
inlinenoexcept

◆ ~Future()

template<typename T >
nros::Future< T >::~Future ( )
inline

◆ Future() [2/2]

template<typename T >
nros::Future< T >::Future ( )
inline

Default constructor – creates an empty/consumed future.

Member Function Documentation

◆ cancel()

template<typename T >
void nros::Future< T >::cancel ( )
inline

Cancel the pending operation (idempotent).

◆ is_consumed()

template<typename T >
bool nros::Future< T >::is_consumed ( ) const
inline

Check if the future has been consumed or cancelled.

◆ is_ready()

template<typename T >
bool nros::Future< T >::is_ready ( )
inline

Check if the result has arrived (non-blocking).

◆ operator=()

template<typename T >
Future & nros::Future< T >::operator= ( Future< T > &&  other)
inlinenoexcept

◆ try_take()

template<typename T >
Result nros::Future< T >::try_take ( T out)
inline

Take the result if ready, consuming the future.

Parameters
outOutput object (filled on success).
Returns
Result::success() on ready, ErrorCode::Error if not ready or failed.

◆ wait()

template<typename T >
Result nros::Future< T >::wait ( void executor_handle,
uint32_t  timeout_ms,
T out,
uint32_t  poll_ms = 10 
)
inline

Block until the result arrives, spinning the executor.

Parameters
executor_handleRaw executor handle (Executor::handle() or global).
timeout_msMaximum wait time in milliseconds.
outOutput object (filled on success).
poll_msPer-iteration spin_once timeout in ms (default 10). Smaller values give lower latency when the reply arrives mid-step but wake the executor more often; larger values reduce wakeups for long waits.
Returns
Result::success(), ErrorCode::Timeout, or error.

Friends And Related Symbol Documentation

◆ ActionClient

template<typename T >
template<typename A >
friend class ActionClient
friend

◆ Client

template<typename T >
template<typename S >
friend class Client
friend

The documentation for this class was generated from the following file: