ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
response_channel Class Referencefinal

Single-value async channel for delivering a response frame. More...

#include <response_channel.hpp>

Collaboration diagram for response_channel:
Collaboration graph

Public Member Functions

 response_channel (boost::asio::any_io_executor executor)
 
 response_channel (const response_channel &)=delete
 
response_channeloperator= (const response_channel &)=delete
 
 response_channel (response_channel &&)=delete
 
response_channeloperator= (response_channel &&)=delete
 
void set_value (messaging::frame response)
 Set the response value (producer side).
 
void set_error (messaging::error_code ec)
 Set an error (producer side).
 
boost::asio::awaitable< std::expected< messaging::frame, messaging::error_code > > get ()
 Wait for and retrieve the response (consumer side).
 
bool is_ready () const
 Check if the channel has already received a value or error.
 

Detailed Description

Single-value async channel for delivering a response frame.

Used by the message loop to deliver responses to waiting co-routines. Each channel can hold exactly one response (or error). The consumer calls get() which blocks until set_value() or set_error() is called by the producer (message loop).

Uses a steady_timer as the signaling primitive - a common Boost.Asio pattern for implementing async channels without std::experimental features.

Member Function Documentation

◆ set_value()

void set_value ( messaging::frame  response)

Set the response value (producer side).

Called by the message loop when a response arrives. Wakes up the waiting get() coroutine.

Parameters
responseThe response frame to deliver

◆ set_error()

void set_error ( messaging::error_code  ec)

Set an error (producer side).

Called by the message loop on timeout or disconnect. Wakes up the waiting get() coroutine with an error.

Parameters
ecThe error code to deliver

◆ get()

boost::asio::awaitable< std::expected< messaging::frame, messaging::error_code > > get ( )

Wait for and retrieve the response (consumer side).

Blocks until set_value() or set_error() is called.

Returns
Expected containing the response frame, or error_code