cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
mcp::core::AsyncResult< T > Class Template Reference

A thread-safe, CV-based future that replaces std::promise/shared_future. More...

#include <async_result.hpp>

Public Types

using ResultType = Result< T >
 

Public Member Functions

 AsyncResult (const AsyncResult &)=delete
 
AsyncResultoperator= (const AsyncResult &)=delete
 
void set_value (T value)
 Set the result value.
 
void set_error (Error error)
 Set an error result. Notifies all waiters and fires continuations.
 
void cancel (std::string reason={})
 Cancel the result with a cancellation error. Notifies all waiters.
 
void set_exception (std::exception_ptr ex)
 Set the result from an exception_ptr.
 
ResultType wait () const
 Block until the result is available. CV-based, no polling.
 
ResultType wait_for (std::chrono::milliseconds timeout) const
 Block until the result is available or the timeout expires.
 
ResultType wait_until (std::chrono::steady_clock::time_point deadline) const
 Block until the result is available or the deadline is reached.
 
bool ready () const
 Returns true if the result has been set.
 
template<class F >
auto then (F &&callback) -> std::shared_ptr< AsyncResult< std::invoke_result_t< F, ResultType > > >
 Chain a continuation that fires when the result is set.
 

Detailed Description

template<class T>
class mcp::core::AsyncResult< T >

A thread-safe, CV-based future that replaces std::promise/shared_future.

AsyncResult<T> provides condition-variable-based waiting (no polling), cancellation support, and optional continuation chaining via then().

Template Parameters
TThe value type. The result is always stored as Result<T>.

Member Function Documentation

◆ set_value()

template<class T >
void mcp::core::AsyncResult< T >::set_value ( value)
inline

Set the result value.

Notifies all waiters and fires continuations. Must be called at most once.

◆ then()

template<class T >
template<class F >
auto mcp::core::AsyncResult< T >::then ( F &&  callback) -> std::shared_ptr<AsyncResult<std::invoke_result_t<F, ResultType>>>
inline

Chain a continuation that fires when the result is set.

If the result is already set, the callback fires immediately on the calling thread. Otherwise it is stored and invoked on the thread that calls set_value/set_error/cancel.

Template Parameters
FCallable with signature R(Result<T>).
Returns
A new AsyncResult holding the callback's return value.

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